Sample plugin does not start

This topic has been viewed 6523 times and has 4 replies
Thread status: Active
Questions about extending features and developing plug-ins [img]http://www.sweethome3d.com/images/flags/en_small.gif[/img]
Post Reply New Topic
cungchoi
Newbie
Posts: 3
Joined: Fri Dec 19, 2014 4:47 am

Sample plugin does not start

Post by cungchoi »

I followed exactly the Plugin development guide and created VolumePlugin.jar in plugin folder.
However when I opened the main Sweethome3d, it stays the start up picture forever.
I tried changing JRE package (I have v6, v7 on my Win7) but no help.
Any ideas? thanks
User avatar
Puybaret
Expert
Posts: 9440
Joined: Mon Nov 07, 2005 12:00 pm
Country: Paris, France
Contact:

Re: Sample plugin does not start

Post by Puybaret »

Check the console, there must be a stack trace that appears in it.
Emmanuel Puybaret, Sweet Home 3D creator
cungchoi
Newbie
Posts: 3
Joined: Fri Dec 19, 2014 4:47 am

Re: Sample plugin does not start

Post by cungchoi »

thank you, I think I did a wrong thing to run the Sweethome3d.exe instead of its Jar version. Will try again.
User avatar
Puybaret
Expert
Posts: 9440
Joined: Mon Nov 07, 2005 12:00 pm
Country: Paris, France
Contact:

Re: Sample plugin does not start

Post by Puybaret »

Plug-ins can run from Sweethome3d.exe too, but in case of problems, you should rather use the Jar version to check the console.
Emmanuel Puybaret, Sweet Home 3D creator
cungchoi
Newbie
Posts: 3
Joined: Fri Dec 19, 2014 4:47 am

Re: Sample plugin does not start

Post by cungchoi »

Right, I think my exe file is not up to date. Fine now though.
BTW, I modified your plugin Compute Walls Surface for my purpose and just for it (being messy of course), still I post it here if anyone bother to test or use it.
don't know how to attach a file

Code: Select all

//version 25 Dec 2014 
//- added ability to approximate curved walls
//- added ability to work for multilevel building
//- corrected slope walls
//- filter openings substractions by Doors & windows only
//- approximate doors & windows positions to prefer more inclusions. CAUTION: may have side effects when a door or windows is in vicinity of more than one wall on any level

package com.eteks.calculateWalls;

import java.awt.geom.Point2D;
import java.lang.reflect.Method;
import java.util.ArrayList;

import com.eteks.sweethome3d.model.HomePieceOfFurniture;
import com.eteks.sweethome3d.model.Selectable;
import com.eteks.sweethome3d.model.Wall;
import com.eteks.sweethome3d.plugin.Plugin;
import com.eteks.sweethome3d.plugin.PluginAction;

import javax.swing.JOptionPane;


class CalculateWallsAction  extends PluginAction {

    private final Plugin plugin;

    public CalculateWallsAction(ClassLoader loader, Plugin plugin){
    	putPropertyValue(Property.NAME, "Compute walls' area");
        putPropertyValue(Property.MENU, "Tools");
        
        this.plugin = plugin;
        // Enables the action by default
        setEnabled(true);
    }

    private void showInfo(float size) {
        String message = "The walls' area currently is: "+size+" m\u00B2.";
    	if(size == 0)
    	{
    		message = "Please select at least one wall.";
    	}
        JOptionPane.showMessageDialog(null, message);
    }
    
    private boolean inWall(Wall w, float x, float y)
    {
    	//if(x >= Math.min(w.getXStart(), w.getXEnd()) && x <= Math.max(w.getXStart(), w.getXEnd()) && y >= Math.min(w.getYStart(), w.getYEnd()) && y <= Math.max(w.getYStart(), w.getYEnd()))
      float cmpRate = 0;
   	//generalize- just one end near the wall surface, there are two cases:
   	//case 1: an arc wall
      if(w.getArcExtent() != null)
      {
    	  float [] arcCircleCenter;
    	  float arcCircleRadius;
    	  try{ 
	          Method m = Wall.class.getDeclaredMethod("getArcCircleCenter");
	          //m.invoke(d);// throws java.lang.IllegalAccessException
	          m.setAccessible(true);// Abracadabra
	          arcCircleCenter = (float[]) m.invoke(w);// now its OK
	          arcCircleRadius = (float)Point2D.distance(w.getXStart(), w.getYStart(), 
	    	          arcCircleCenter [0], arcCircleCenter [1]);
		      cmpRate =(float)Point2D.distance(x,y,arcCircleCenter [0], arcCircleCenter [1])/arcCircleRadius;
	      } catch (Exception e) {
	          e.printStackTrace();
	      }
      }
      else
      {
	      float dist2Start = (float)Point2D.distance(x,y,w.getXStart(), w.getYStart()); 
	      cmpRate = (dist2Start + (float)Point2D.distance(x,y,w.getXEnd(), w.getYEnd()))/w.getLength(); 
    	}
	   if((cmpRate > 0.9)&&(cmpRate< 1.1)) return true;
    	return false;
    }

    @Override
    public void execute() {
    	float size = 0;
    	
    	ArrayList<Wall> walls = new ArrayList<Wall>();
    	for(Selectable sel : plugin.getHome().getSelectedItems())
    	{
    		if(sel instanceof Wall)
    		{
    			Wall wall = (Wall) sel;
    			
    			//if(wall.getArcExtent() == null)
				walls.add(wall);
    			size += (wall.getHeight() + ((wall.getHeightAtEnd()==null)? wall.getHeight():wall.getHeightAtEnd()) )*wall.getLength()/2.0;

    	    	//substracts openings
    			for(HomePieceOfFurniture furniture : plugin.getHome().getFurniture())
	        	if(furniture.isDoorOrWindow() 
	        			&& wall.isAtLevel(furniture.getLevel())
	        			&& inWall(wall, furniture.getX(), furniture.getY()))
        			size -= (furniture.getHeight()*furniture.getWidth());
    		
    		}
    	}
    	
    	size /= 10000;
    	showInfo(size);
    }
}
Post Reply New Topic

Who is online

Users browsing this forum: No registered users