1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : PrimitiveGUI.cxx
25 // Author : Damien COQUERET
30 #include "PrimitiveGUI.h"
32 #include "SALOMEGUI_QtCatchCorbaException.hxx"
33 #include <Precision.hxx>
35 #include "PrimitiveGUI_BoxDlg.h" // Method BOX
36 #include "PrimitiveGUI_CylinderDlg.h" // Method CYLINDER
37 #include "PrimitiveGUI_SphereDlg.h" // Method SPHERE
38 #include "PrimitiveGUI_TorusDlg.h" // Method TORUS
39 #include "PrimitiveGUI_ConeDlg.h" // Method CONE
41 //=======================================================================
42 // function : PrimitiveGUI()
43 // purpose : Constructor
44 //=======================================================================
45 PrimitiveGUI::PrimitiveGUI() :
48 myGeomBase = new GEOMBase();
49 myGeomGUI = GEOMContext::GetGeomGUI();
50 myGeom = myGeomGUI->myComponentGeom;
54 //=======================================================================
55 // function : ~PrimitiveGUI()
56 // purpose : Destructor
57 //=======================================================================
58 PrimitiveGUI::~PrimitiveGUI()
63 //=======================================================================
64 // function : OnGUIEvent()
66 //=======================================================================
67 bool PrimitiveGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent)
69 PrimitiveGUI* aPrimitiveGUI = new PrimitiveGUI();
70 aPrimitiveGUI->myGeomGUI->EmitSignalDeactivateDialog();
71 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
76 PrimitiveGUI_BoxDlg* aDlg = new PrimitiveGUI_BoxDlg(parent, "", aPrimitiveGUI, Sel);
79 case 4022: // CYLINDER
81 PrimitiveGUI_CylinderDlg* aDlg = new PrimitiveGUI_CylinderDlg(parent, "", aPrimitiveGUI, Sel);
86 PrimitiveGUI_SphereDlg* aDlg = new PrimitiveGUI_SphereDlg(parent, "", aPrimitiveGUI, Sel);
91 PrimitiveGUI_TorusDlg* aDlg = new PrimitiveGUI_TorusDlg(parent, "", aPrimitiveGUI, Sel);
96 PrimitiveGUI_ConeDlg* aDlg = new PrimitiveGUI_ConeDlg(parent, "", aPrimitiveGUI, Sel);
101 parent->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
109 //=======================================================================
110 // function : MakeBoxAndDisplay()
112 //=======================================================================
113 void PrimitiveGUI::MakeBoxAndDisplay(const gp_Pnt P1, const gp_Pnt P2)
116 GEOM::GEOM_Shape_var box = myGeom->MakeBox(P1.X(), P1.Y(), P1.Z(), P2.X(), P2.Y(), P2.Z());
117 box->NameType(tr("GEOM_BOX"));
118 if(myGeomBase->Display(box))
119 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
121 catch(const SALOME::SALOME_Exception& S_ex) {
122 QtCatchCorbaException(S_ex);
127 //=====================================================================================
128 // function : MakeCylinderAndDisplay()
130 //=====================================================================================
131 void PrimitiveGUI::MakeCylinderAndDisplay(const gp_Pnt BasePoint, const gp_Dir aDir,
132 const double Radius, const double aHeight)
135 if(Radius <= Precision::Confusion() || aHeight <= Precision::Confusion())
138 GEOM::PointStruct pstruct = myGeom->MakePointStruct(BasePoint.X(), BasePoint.Y(), BasePoint.Z());
139 GEOM::PointStruct d = myGeom->MakePointStruct(aDir.X(), aDir.Y(), aDir.Z());
140 GEOM::DirStruct dstruct = myGeom->MakeDirection(d);
142 GEOM::GEOM_Shape_var result = myGeom->MakeCylinder(pstruct, dstruct, Radius, aHeight);
143 if (result->_is_nil()) {
144 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
147 result->NameType(tr("GEOM_CYLINDER"));
148 if(myGeomBase->Display(result))
149 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
151 catch(const SALOME::SALOME_Exception& S_ex) {
152 QtCatchCorbaException(S_ex);
158 //=====================================================================================
159 // function : MakeSphere()
161 //=====================================================================================
162 void PrimitiveGUI::MakeSphereAndDisplay(const gp_Pnt aCenterPoint, const double aRadius)
165 if(aRadius <= Precision::Confusion())
168 GEOM::GEOM_Shape_ptr result = myGeom->MakeSphere(aCenterPoint.X(),aCenterPoint.Y(),aCenterPoint.Z(), aRadius);
169 result->NameType(tr("GEOM_SPHERE"));
170 if (myGeomBase->Display(result))
171 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
173 catch (const SALOME::SALOME_Exception& S_ex) {
174 QtCatchCorbaException(S_ex);
180 //=====================================================================================
181 // function : MakeTorusAndDisplay()
183 //=====================================================================================
184 void PrimitiveGUI::MakeTorusAndDisplay(const gp_Pnt BasePoint, const gp_Dir aDir,
185 const double Radius1, const double Radius2)
188 if(Radius1 <= Precision::Confusion() || Radius2 <= Precision::Confusion())
191 GEOM::PointStruct pstruct = myGeom->MakePointStruct(BasePoint.X(), BasePoint.Y(), BasePoint.Z());
192 GEOM::PointStruct d = myGeom ->MakePointStruct(aDir.X(), aDir.Y(), aDir.Z());
193 GEOM::DirStruct dstruct = myGeom->MakeDirection(d);
195 GEOM::GEOM_Shape_var result = myGeom->MakeTorus(pstruct, dstruct, Radius1, Radius2);
196 if(result->_is_nil()) {
197 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
200 result->NameType(tr("GEOM_TORUS"));
201 if(myGeomBase->Display(result))
202 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
204 catch(const SALOME::SALOME_Exception& S_ex) {
205 QtCatchCorbaException(S_ex);
211 //=====================================================================================
212 // function : MakeConeAndDisplay()
214 //=====================================================================================
215 void PrimitiveGUI::MakeConeAndDisplay(const gp_Pnt BasePoint, const gp_Dir aDir,
216 const double Radius1, const double Radius2, const double aHeight)
219 if((Radius1 <= Precision::Confusion() && Radius2 <= Precision::Confusion()) || aHeight <= Precision::Confusion())
222 GEOM::PointStruct pstruct = myGeom->MakePointStruct(BasePoint.X(), BasePoint.Y(), BasePoint.Z());
223 GEOM::PointStruct d = myGeom->MakePointStruct(aDir.X(), aDir.Y(), aDir.Z());
224 GEOM::DirStruct dstruct = myGeom->MakeDirection(d);
226 GEOM::GEOM_Shape_var result = myGeom->MakeCone(pstruct, dstruct, Radius1, Radius2, aHeight);
227 if(result->_is_nil()) {
228 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
231 result->NameType(tr("GEOM_CONE"));
232 if(myGeomBase->Display(result))
233 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
235 catch(const SALOME::SALOME_Exception& S_ex) {
236 QtCatchCorbaException(S_ex);
242 //=====================================================================================
244 //=====================================================================================
247 bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
248 {return PrimitiveGUI::OnGUIEvent(theCommandID, parent);}