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 : OperationGUI.cxx
25 // Author : Damien COQUERET
30 #include "OperationGUI.h"
32 #include "DisplayGUI.h"
34 #include "QAD_RightFrame.h"
35 #include "OCCViewer_Viewer3d.h"
36 #include "OCCViewer_ViewFrame.h"
37 #include "SALOMEGUI_QtCatchCorbaException.hxx"
39 #include <TopTools_MapOfShape.hxx>
40 #include <TopExp_Explorer.hxx>
41 #include <Precision.hxx>
43 #include "OperationGUI_PartitionDlg.h" // Method PARTITION
44 #include "OperationGUI_ArchimedeDlg.h" // Method ARCHIMEDE
45 #include "OperationGUI_FilletDlg.h" // Method FILLET
46 #include "OperationGUI_ChamferDlg.h" // Method CHAMFER
48 //=======================================================================
49 // function : OperationGUI()
50 // purpose : Constructor
51 //=======================================================================
52 OperationGUI::OperationGUI() :
55 myGeomBase = new GEOMBase();
56 myGeomGUI = GEOMContext::GetGeomGUI();
57 myGeom = myGeomGUI->myComponentGeom;
61 //=======================================================================
62 // function : ~OperationGUI()
63 // purpose : Destructor
64 //=======================================================================
65 OperationGUI::~OperationGUI()
70 //=======================================================================
71 // function : OnGUIEvent()
73 //=======================================================================
74 bool OperationGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent)
76 OperationGUI* myOperationGUI = new OperationGUI();
77 myOperationGUI->myGeomGUI->EmitSignalDeactivateDialog();
78 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
82 case 503: // PARTITION
84 OperationGUI_PartitionDlg *aDlg = new OperationGUI_PartitionDlg(parent, "", myOperationGUI, Sel);
87 case 504: // ARCHIMEDE
89 OperationGUI_ArchimedeDlg *aDlg = new OperationGUI_ArchimedeDlg(parent, "", myOperationGUI, Sel);
94 Handle(AIS_InteractiveContext) ic;
95 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
96 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
97 ic = v3d->getAISContext();
99 OperationGUI_FilletDlg *aDlg = new OperationGUI_FilletDlg(parent, "", myOperationGUI, Sel, ic);
104 Handle(AIS_InteractiveContext) ic;
105 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
106 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
107 ic = v3d->getAISContext();
109 OperationGUI_ChamferDlg *aDlg = new OperationGUI_ChamferDlg(parent, "", myOperationGUI, Sel, ic);
114 parent->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
122 //=====================================================================================
123 // function : MakePartitionAndDisplay()
125 //=====================================================================================
126 void OperationGUI::MakePartitionAndDisplay(const GEOM::GEOM_Gen::ListOfIOR& listShapesIOR,
127 const GEOM::GEOM_Gen::ListOfIOR& listToolsIOR,
128 const GEOM::GEOM_Gen::ListOfIOR& listKeepInsIOR,
129 const GEOM::GEOM_Gen::ListOfIOR& listRemoveInsIOR,
130 const GEOM::shape_type limit)
133 GEOM::GEOM_Shape_var result = myGeom->Partition(listShapesIOR, listToolsIOR,
134 listKeepInsIOR, listRemoveInsIOR,
135 (CORBA::Short) limit);
136 if(result->_is_nil()) {
137 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_NULLSHAPE"));
140 result->NameType(tr("GEOM_PARTITION"));
141 if(myGeomBase->Display(result))
142 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
145 catch(const SALOME::SALOME_Exception& S_ex) {
146 QtCatchCorbaException(S_ex);
151 //=======================================================================
152 // function : Archimede()
154 //=======================================================================
155 void OperationGUI::Archimede(const Handle(SALOME_InteractiveObject)& IO, const double aWeight,
156 const double aWaterDensity, const double aMeshingDeflection)
159 if(IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject))) {
160 Handle(GEOM_InteractiveObject) GIO = Handle(GEOM_InteractiveObject)::DownCast(IO);
161 GEOM::GEOM_Shape_var Shape = myGeom->GetIORFromString(GIO->getIOR());
163 GEOM::GEOM_Shape_var Result = myGeom->Archimede(Shape, aWeight, aWaterDensity, aMeshingDeflection);
164 Result->NameType(tr("GEOM_PLANE"));
165 if(myGeomBase->Display(Result)) {
166 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
171 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
172 SALOMEDS::SObject_var obj = aStudy->FindObjectID( IO->getEntry());
173 SALOMEDS::GenericAttribute_var anAttr;
174 SALOMEDS::AttributeIOR_var anIOR;
175 if(!obj->_is_nil()) {
176 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
177 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
178 GEOM::GEOM_Shape_var Shape = myGeom->GetIORFromString(anIOR->Value());
179 GEOM::GEOM_Shape_var Result = myGeom->Archimede(Shape, aWeight, aWaterDensity, aMeshingDeflection);
180 Result->NameType(tr("GEOM_PLANE"));
181 if (myGeomBase->Display(Result)) {
182 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
188 catch(const SALOME::SALOME_Exception& S_ex) {
189 QtCatchCorbaException(S_ex);
194 //=====================================================================================
195 // function : OnFilletGetAll()
197 //=====================================================================================
198 bool OperationGUI::OnFilletGetAll(const TopoDS_Shape& ShapeTopo, const double Radius,
199 const int SubShapeType, const char* ShapeTopoIOR)
201 GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID;
204 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
205 SALOMEDS::SObject_var theObj = aStudy->FindObjectIOR(ShapeTopoIOR);
206 if(theObj->_is_nil()) {
207 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY"));
212 if(Radius <= Precision::Confusion())
215 GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(ShapeTopoIOR);
216 GEOM::GEOM_Shape_var result = myGeom->MakeFillet(aShape, Radius, SubShapeType, ListOfID);
217 if(result->_is_nil()) {
218 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
221 TopoDS_Shape S = myGeomGUI->GetShapeReader().GetShape(myGeom, result);
222 Standard_CString type;
223 myGeomBase->GetShapeTypeString(S,type);
224 result->NameType(type);
226 if(myGeomBase->Display(result))
227 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
229 catch (const SALOME::SALOME_Exception& S_ex) {
230 QtCatchCorbaException(S_ex);
236 //=====================================================================================
237 // function : OnFilletGetSelected()
239 //=====================================================================================
240 bool OperationGUI::OnFilletGetSelected(const TopoDS_Shape& ShapeTopo, const char* ShapeTopoIOR,
241 const double Radius, const int SubShapeType,
242 Standard_Integer& aLocalContextId, bool& myUseLocalContext)
244 if (QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
247 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
248 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
250 if(myUseLocalContext == false) {
251 /* No local context opened for fillet method */
252 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
256 GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID;
258 int nbSelected = ic->NbSelected();
262 while(ic->MoreSelected()) {
263 TopoDS_Shape s = ic->SelectedShape();
264 if(s.ShapeType() == TopAbs_FACE) {
265 TopExp_Explorer Exp(s, TopAbs_EDGE);
266 TopTools_MapOfShape M;
268 if(M.Add(Exp.Current())) { /* if a new edge : do not add doublons indices */
269 ListOfID->length(i + 1);
270 ListOfID[i] = myGeomBase->GetIndex(Exp.Current(), ShapeTopo, (int)TopAbs_EDGE);
277 ListOfID->length(i + 1);
278 ListOfID[i] = myGeomBase->GetIndex(ic->SelectedShape(), ShapeTopo, SubShapeType);
284 GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(ShapeTopoIOR);
285 GEOM::GEOM_Shape_var aResult;
287 aResult = myGeom->MakeFillet(aShape, Radius, 6, ListOfID);
289 /* local context from DialogBox */
290 ic->CloseLocalContext(aLocalContextId);
291 myUseLocalContext = false;
293 TopoDS_Shape S = myGeomGUI->GetShapeReader().GetShape(myGeom, aResult);
294 Standard_CString type;
295 myGeomBase->GetShapeTypeString(S,type);
296 aResult->NameType(type);
298 if(myGeomBase->Display(aResult))
299 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
301 catch(const SALOME::SALOME_Exception& S_ex) {
302 QtCatchCorbaException(S_ex);
305 if(myUseLocalContext) {
306 /* local context from DialogBox */
307 ic->CloseLocalContext(aLocalContextId);
308 myUseLocalContext = false;
311 DisplayGUI* myDisplayGUI = new DisplayGUI();
312 myDisplayGUI->OnDisplayAll(true) ;
313 QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser();
314 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_READY"));
320 //=====================================================================================
321 // function : OnChamferGetAll()
323 //=====================================================================================
324 bool OperationGUI::OnChamferGetAll(const TopoDS_Shape& ShapeTopo, const double D1, const double D2, const int SubShapeType, const char* ShapeTopoIOR)
326 GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID;
329 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
330 SALOMEDS::SObject_var theObj = aStudy->FindObjectIOR(ShapeTopoIOR);
331 if(theObj->_is_nil()) {
332 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY"));
337 if(D1 <= Precision::Confusion())
339 if(D2 <= Precision::Confusion())
342 GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(ShapeTopoIOR);
343 GEOM::GEOM_Shape_var result = myGeom->MakeChamfer(aShape, D1, D2, SubShapeType, ListOfID);
344 if(result->_is_nil()) {
345 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
349 TopoDS_Shape S = myGeomGUI->GetShapeReader().GetShape(myGeom, result);
350 Standard_CString type;
351 myGeomBase->GetShapeTypeString(S,type);
352 result->NameType(type);
354 if(myGeomBase->Display(result))
355 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
357 catch (const SALOME::SALOME_Exception& S_ex) {
358 QtCatchCorbaException(S_ex);
364 //=====================================================================================
365 // function : OnChamferGetSelected()
367 //=====================================================================================
368 bool OperationGUI::OnChamferGetSelected(const TopoDS_Shape& ShapeTopo, const char* ShapeTopoIOR,
369 const double D1, const double D2, const int SubShapeType,
370 Standard_Integer& aLocalContextId, bool& myUseLocalContext)
372 if (QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
375 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
376 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
378 if(myUseLocalContext == false) {
379 /* No local context opened for chamfer method */
380 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
384 GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID;
386 int nbSelected = ic->NbSelected();
390 while(ic->MoreSelected()) {
391 TopoDS_Shape s = ic->SelectedShape();
392 if (s.ShapeType() == TopAbs_FACE) {
393 TopExp_Explorer Exp(s, TopAbs_EDGE);
394 TopTools_MapOfShape M;
396 if(M.Add(Exp.Current())) { /* if a new edge : do not add doublons indices */
397 ListOfID->length(i + 1);
398 ListOfID[i] = myGeomBase->GetIndex(Exp.Current(), ShapeTopo, (int)TopAbs_EDGE);
405 ListOfID->length(i + 1);
406 ListOfID[i] = myGeomBase->GetIndex(ic->SelectedShape(), ShapeTopo, SubShapeType);
412 GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(ShapeTopoIOR);
413 GEOM::GEOM_Shape_var aResult;
415 aResult = myGeom->MakeChamfer(aShape, D1, D2, 6, ListOfID);
417 /* local context from DialogBox */
418 ic->CloseLocalContext(aLocalContextId);
419 myUseLocalContext = false;
421 TopoDS_Shape S = myGeomGUI->GetShapeReader().GetShape(myGeom, aResult);
422 Standard_CString type;
423 myGeomBase->GetShapeTypeString(S,type);
424 aResult->NameType(type);
426 if(myGeomBase->Display(aResult))
427 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
429 catch(const SALOME::SALOME_Exception& S_ex) {
430 QtCatchCorbaException(S_ex);
433 if (myUseLocalContext) {
434 /* local context from DialogBox */
435 ic->CloseLocalContext(aLocalContextId);
436 myUseLocalContext = false;
439 DisplayGUI* myDisplayGUI = new DisplayGUI();
440 myDisplayGUI->OnDisplayAll(true) ;
441 QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser();
442 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_READY"));
448 //=====================================================================================
450 //=====================================================================================
453 bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
454 {return OperationGUI::OnGUIEvent(theCommandID, parent);}