root/trunk/Moonlight/src/eu/moonlight3d/ml3d/modelling/mesh/CreateConeCommand.java

Revision 1221, 3.8 kB (checked in by gregor, 7 months ago)

fixed exception when creating cone

Line 
1 /*
2  * Moonlight|3D
3  * Copyright (C) 2009 The Moonlight|3D team
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18  *
19  * Created on Nov 29, 2009
20  */
21
22 package eu.moonlight3d.ml3d.modelling.mesh;
23
24 import eu.moonlight3d.common.ui.command.Command;
25 import eu.moonlight3d.framework.State;
26 import eu.moonlight3d.framework.localization.L10N;
27 import eu.moonlight3d.framework.properties.FloatValue;
28 import eu.moonlight3d.framework.properties.IntegerValue;
29 import eu.moonlight3d.framework.ui.ExceptionDialog;
30 import eu.moonlight3d.ml3d.backend.selection.Selection;
31 import eu.moonlight3d.ml3d.backend.threedim.document.Document;
32 import eu.moonlight3d.ml3d.backend.threedim.helper.OperatorGraphHelper;
33 import eu.moonlight3d.ml3d.backend.threedim.og.Manager;
34 import eu.moonlight3d.ml3d.backend.threedim.og.Node;
35 import eu.moonlight3d.ml3d.ui.command.CommandBase;
36
37 /**
38  * Create Cone command for the command stack
39  *
40  * @author gregor
41  */
42 public class CreateConeCommand extends CommandBase implements Command {
43         /**
44          * Radius of the cone
45          */
46         private double radius;
47         /**
48          * Height of the cone
49          */
50         private double height;
51         /**
52          * Number of divisions
53          */
54         private int divisionsU;
55         /**
56          * Name of the created OG node for undo
57          */
58         private String createConeNodeName;
59        
60         /**
61          * Constructor taking values from tool option editor as arguments
62          *
63          * @param radius cone radius
64          * @param height cone height
65          * @param divisionsU cone subdivision
66          */
67         public CreateConeCommand(double radius, double height, int divisionsU) {
68                 this.radius=radius;
69                 this.height=height;
70                 this.divisionsU=divisionsU;
71         }
72
73         public boolean execute() {
74         redo();         
75         return true;
76         }
77
78         public String getBriefDescription() {
79                 return L10N.translate("Create Cone");
80         }
81
82         public boolean isUndoable() {
83                 return true;
84         }
85
86         public void redo() {
87         State state=eu.moonlight3d.framework.State.getInstance();
88         Manager ogManager = ((Document) state.getDocumentManager().getMainDocument()).getOGManager();
89         try {
90                 saveOldSelection();
91                
92                         Node createCone=ogManager.createNodeByName("CreateCone");
93                         createConeNodeName=createCone.getName();
94                 createCone.getProperty("radius").setValue(new FloatValue(radius));
95                 createCone.getProperty("height").setValue(new FloatValue(height));
96                 createCone.getProperty("divisionsU").setValue(new IntegerValue(divisionsU));
97                         ogManager.update();
98
99                         Selection selection=((Document) state.getDocumentManager().getMainDocument()).getSelectionManager().getSelection("viewSelection");
100                 selection.clearSelection(eu.moonlight3d.ml3d.backend.selection.Manager.getSelectionType("SGNode"));
101                 selection.add("OperatorGraph/" + createConeNodeName + "/output/ConeInstance");
102                 } catch (Exception e) {
103                         ExceptionDialog.run(e);
104                 }
105         }
106
107         public void undo() {
108         State state=eu.moonlight3d.framework.State.getInstance();
109         Manager ogManager = ((Document) state.getDocumentManager().getMainDocument()).getOGManager();
110         try {
111                 restoreOldSelection();
112                 OperatorGraphHelper.remove(createConeNodeName);
113                 ogManager.update();
114                 } catch (Exception e) {
115                         ExceptionDialog.run(e);
116                 }
117         }
118
119 }
Note: See TracBrowser for help on using the browser.