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 : RepairGUI.cxx
25 // Author : Damien COQUERET
30 #include "RepairGUI.h"
32 #include "QAD_RightFrame.h"
33 #include "OCCViewer_Viewer3d.h"
34 #include "SALOMEGUI_QtCatchCorbaException.hxx"
36 #include "RepairGUI_SewingDlg.h" // Method SEWING
37 #include "RepairGUI_OrientationDlg.h" // Method ORIENTATION
38 #include "RepairGUI_SuppressFacesDlg.h" // Method SUPPRESS FACES
39 #include "RepairGUI_SuppressHoleDlg.h" // Method SUPPRESS HOLE
41 //=======================================================================
42 // function : RepairGUI()
43 // purpose : Constructor
44 //=======================================================================
45 RepairGUI::RepairGUI() :
48 myGeomBase = new GEOMBase();
49 myGeomGUI = GEOMContext::GetGeomGUI();
50 // Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
51 // myGeom = GEOM::GEOM_Gen::_narrow(comp);
52 myGeom = myGeomGUI->myComponentGeom;
56 //=======================================================================
57 // function : ~RepairGUI()
58 // purpose : Destructor
59 //=======================================================================
60 RepairGUI::~RepairGUI()
65 //=======================================================================
66 // function : OnGUIEvent()
68 //=======================================================================
69 bool RepairGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent)
71 RepairGUI* myRepairGUI = new RepairGUI();
72 myRepairGUI->myGeomGUI->EmitSignalDeactivateDialog();
73 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
79 RepairGUI_SewingDlg *aDlg = new RepairGUI_SewingDlg(parent, "", myRepairGUI, Sel);
82 case 602: // ORIENTATION
84 RepairGUI_OrientationDlg *aDlg = new RepairGUI_OrientationDlg(parent, "", myRepairGUI, Sel);
87 case 603: // SUPPRESS FACES : use ic
89 Handle(AIS_InteractiveContext) ic;
90 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
91 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
92 ic = v3d->getAISContext();
94 RepairGUI_SuppressFacesDlg *aDlg = new RepairGUI_SuppressFacesDlg(parent, "", myRepairGUI, Sel, ic);
97 case 604: // SUPPRESS HOLES : use ic
99 Handle(AIS_InteractiveContext) ic;
100 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
101 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
102 ic = v3d->getAISContext();
104 RepairGUI_SuppressHoleDlg *aDlg = new RepairGUI_SuppressHoleDlg(parent, "", myRepairGUI, Sel, ic);
109 parent->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
117 //=====================================================================================
118 // function : MakeSewingAndDisplay()
120 //=====================================================================================
121 void RepairGUI::MakeSewingAndDisplay(GEOM::GEOM_Gen::ListOfIOR& listShapesIOR,
122 const Standard_Real precision)
125 GEOM::GEOM_Shape_var result = myGeom->MakeSewing(listShapesIOR, precision);
126 if(result->_is_nil()) {
127 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_NULLSHAPE"));
131 TopoDS_Shape S = myGeomGUI->GetShapeReader().GetShape(myGeom, result);
132 Standard_CString type;
133 myGeomBase->GetShapeTypeString(S,type);
134 result->NameType(type);
136 if(myGeomBase->Display(result))
137 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
140 catch(const SALOME::SALOME_Exception& S_ex) {
141 QtCatchCorbaException(S_ex);
147 //=====================================================================================
148 // function : MakeOrientationChangeAndDisplay()
150 //=====================================================================================
151 void RepairGUI::MakeOrientationChangeAndDisplay(GEOM::GEOM_Shape_ptr Shape)
154 GEOM::GEOM_Shape_var result = myGeom->OrientationChange(Shape);
155 if(result->_is_nil()) {
156 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_NULLSHAPE"));
159 result->NameType(Shape->NameType());
160 if(myGeomBase->Display(result))
161 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
164 catch(const SALOME::SALOME_Exception& S_ex) {
165 QtCatchCorbaException(S_ex);
171 //=====================================================================================
172 // function : OnSuppressHole()
173 // purpose : To suppress an hole on a shape 'ShapeTopo'.
174 // : 'ListOfIdEndFace' may be an empty list.
175 // : This means that hole do not traverse ShapeTopo.
176 // : Warning : the hole to be suppressed must be defined by one or two single closed wires !
177 //=====================================================================================
178 bool RepairGUI::OnSuppressHole(const char* ShapeTopoIOR,
179 const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfIdFace,
180 const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfIdWire,
181 const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfIdEndFace)
183 /* Test the type of viewer */
184 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC )
188 GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(ShapeTopoIOR);
189 GEOM::GEOM_Shape_var aResult = myGeom->SuppressHole(aShape, ListOfIdFace, ListOfIdWire, ListOfIdEndFace);
191 TopoDS_Shape S = myGeomGUI->GetShapeReader().GetShape(myGeom, aResult);
192 Standard_CString type;
193 myGeomBase->GetShapeTypeString(S,type);
194 aResult->NameType(type);
196 if(myGeomBase->Display(aResult))
197 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
199 catch(const SALOME::SALOME_Exception& S_ex) {
200 QtCatchCorbaException(S_ex);
206 //=====================================================================================
207 // function : OnSuppressHolesInFaceOrShell()
208 // purpose : To suppress one or more holes on a face
209 // : 'ListOfIdWires' contains indices or wires/holes.
210 //=====================================================================================
211 bool RepairGUI::OnSuppressHolesInFaceOrShell(const char* ShapeTopoIOR,
212 const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfIdWires)
214 /* Test the type of viewer */
215 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
219 GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(ShapeTopoIOR);
220 GEOM::GEOM_Shape_var aResult = myGeom->SuppressHolesInFaceOrShell(aShape, ListOfIdWires);
222 TopoDS_Shape S = myGeomGUI->GetShapeReader().GetShape(myGeom, aResult);
223 Standard_CString type;
224 myGeomBase->GetShapeTypeString(S,type);
225 aResult->NameType(type);
227 if(myGeomBase->Display(aResult))
228 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
230 catch(const SALOME::SALOME_Exception& S_ex) {
231 QtCatchCorbaException(S_ex);
237 //=====================================================================================
238 // function : OnSuppressFaces()
239 // purpose : To suppress faces from a shape
240 // : The result is one or more shells/faces as main shapes !
241 //=====================================================================================
242 bool RepairGUI::OnSuppressFaces(const TopoDS_Shape& ShapeTopo, const char* ShapeTopoIOR,
243 const Standard_Integer& aLocalContextId, bool& myUseLocalContext)
245 /* Test the type of viewer */
246 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
249 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
250 SALOMEDS::SObject_var theObj = aStudy->FindObjectIOR(ShapeTopoIOR);
251 if(theObj->_is_nil()) {
252 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY"));
256 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
257 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
259 if(myUseLocalContext == false) {
260 /* local context is from DialogBox */
261 MESSAGE("Error : No local context opened for suppress faces method" << endl);
265 GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID;
267 int nbSelected = ic->NbSelected();
268 ListOfID->length(nbSelected);
270 /* Create a list of indices of faces to be suppressed */
272 const int SubShapeType = 4; /* GEOM::FACE type */
273 ic->InitSelected(); /* to repositioning at beginning */
274 while(ic->MoreSelected()) {
275 int index = myGeomBase->GetIndex(ic->SelectedShape(), ShapeTopo, SubShapeType);
281 /* Close local context opened in DialogBox */
282 ic->CloseLocalContext(aLocalContextId);
283 myUseLocalContext = false;
285 /* Here is the main shape */
286 GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(ShapeTopoIOR);
287 GEOM::GEOM_Gen::ListOfGeomShapes_var listGeomShapes = new GEOM::GEOM_Gen::ListOfGeomShapes;
289 /* Call geom method that return a list of shells/faces as result of suppress */
291 listGeomShapes = myGeom->SuppressFaces(aShape, ListOfID);
293 catch(const SALOME::SALOME_Exception& S_ex) {
294 QtCatchCorbaException(S_ex);
297 /* Test list of shells/faces */
298 if(listGeomShapes->length() < 1) {
302 /* Loop on each object created */
303 for(int i=0; i<listGeomShapes->length(); i++) {
304 GEOM::GEOM_Shape_var aShellOrFace = listGeomShapes[i];
305 TopoDS_Shape S = myGeomGUI->GetShapeReader().GetShape(myGeom, aShellOrFace);
310 char* nameG = (char *)malloc(20);
311 Standard_CString Type;
312 if(myGeomBase->GetShapeTypeString(S, Type)) {
313 aShellOrFace->NameType(Type);
314 sprintf (nameG, "%s_%d", Type, myGeomGUI->GetNbGeom()++);
317 aShellOrFace->NameType(tr("GEOM_SHAPE"));
318 sprintf (nameG, "%s_%d", tr("GEOM_SHAPE").latin1(), myGeomGUI->GetNbGeom()++);
321 /* Display with name */
322 if(!myGeomBase->Display(aShellOrFace, nameG)) {
323 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
328 QAD_Application::getDesktop()->putInfo (tr("GEOM_PRP_READY"));
333 //=====================================================================================
335 //=====================================================================================
338 bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
339 {return RepairGUI::OnGUIEvent(theCommandID, parent);}