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
29 #include "RepairGUI.h"
31 #include "QAD_RightFrame.h"
32 #include "OCCViewer_Viewer3d.h"
33 #include "SALOMEGUI_QtCatchCorbaException.hxx"
35 #include "RepairGUI_SewingDlg.h" // Method SEWING
36 #include "RepairGUI_OrientationDlg.h" // Method ORIENTATION
37 #include "RepairGUI_SuppressFacesDlg.h" // Method SUPPRESS FACES
38 #include "RepairGUI_SuppressHoleDlg.h" // Method SUPPRESS HOLE
40 #include "utilities.h"
44 //=======================================================================
45 // function : RepairGUI()
46 // purpose : Constructor
47 //=======================================================================
48 RepairGUI::RepairGUI() :
51 myGeomBase = new GEOMBase();
52 myGeomGUI = GEOMContext::GetGeomGUI();
53 // Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
54 // myGeom = GEOM::GEOM_Gen::_narrow(comp);
55 myGeom = myGeomGUI->myComponentGeom;
59 //=======================================================================
60 // function : ~RepairGUI()
61 // purpose : Destructor
62 //=======================================================================
63 RepairGUI::~RepairGUI()
68 //=======================================================================
69 // function : OnGUIEvent()
71 //=======================================================================
72 bool RepairGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent)
74 RepairGUI* myRepairGUI = new RepairGUI();
75 myRepairGUI->myGeomGUI->EmitSignalDeactivateDialog();
76 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
82 RepairGUI_SewingDlg *aDlg = new RepairGUI_SewingDlg(parent, "", myRepairGUI, Sel);
85 case 602: // ORIENTATION
87 RepairGUI_OrientationDlg *aDlg = new RepairGUI_OrientationDlg(parent, "", myRepairGUI, Sel);
90 case 603: // SUPPRESS FACES : use ic
92 Handle(AIS_InteractiveContext) ic;
93 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
94 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
95 ic = v3d->getAISContext();
97 RepairGUI_SuppressFacesDlg *aDlg = new RepairGUI_SuppressFacesDlg(parent, "", myRepairGUI, Sel, ic);
100 case 604: // SUPPRESS HOLES : use ic
102 Handle(AIS_InteractiveContext) ic;
103 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
104 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
105 ic = v3d->getAISContext();
107 RepairGUI_SuppressHoleDlg *aDlg = new RepairGUI_SuppressHoleDlg(parent, "", myRepairGUI, Sel, ic);
112 parent->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
120 //=====================================================================================
121 // function : MakeSewingAndDisplay()
123 //=====================================================================================
124 void RepairGUI::MakeSewingAndDisplay(GEOM::GEOM_Gen::ListOfIOR& listShapesIOR,
125 const Standard_Real precision)
128 GEOM::GEOM_Shape_var result = myGeom->MakeSewing(listShapesIOR, precision);
129 if(result->_is_nil()) {
130 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_NULLSHAPE"));
134 TopoDS_Shape S = myGeomGUI->GetShapeReader().GetShape(myGeom, result);
135 Standard_CString type;
136 myGeomBase->GetShapeTypeString(S,type);
137 result->NameType(type);
139 if(myGeomBase->Display(result))
140 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
143 catch(const SALOME::SALOME_Exception& S_ex) {
144 QtCatchCorbaException(S_ex);
150 //=====================================================================================
151 // function : MakeOrientationChangeAndDisplay()
153 //=====================================================================================
154 void RepairGUI::MakeOrientationChangeAndDisplay(GEOM::GEOM_Shape_ptr Shape)
157 GEOM::GEOM_Shape_var result = myGeom->OrientationChange(Shape);
158 if(result->_is_nil()) {
159 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_NULLSHAPE"));
162 result->NameType(Shape->NameType());
163 if(myGeomBase->Display(result))
164 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
167 catch(const SALOME::SALOME_Exception& S_ex) {
168 QtCatchCorbaException(S_ex);
174 //=====================================================================================
175 // function : OnSuppressHole()
176 // purpose : To suppress an hole on a shape 'ShapeTopo'.
177 // : 'ListOfIdEndFace' may be an empty list.
178 // : This means that hole do not traverse ShapeTopo.
179 // : Warning : the hole to be suppressed must be defined by one or two single closed wires !
180 //=====================================================================================
181 bool RepairGUI::OnSuppressHole(const char* ShapeTopoIOR,
182 const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfIdFace,
183 const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfIdWire,
184 const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfIdEndFace)
186 /* Test the type of viewer */
187 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC )
191 GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(ShapeTopoIOR);
192 GEOM::GEOM_Shape_var aResult = myGeom->SuppressHole(aShape, ListOfIdFace, ListOfIdWire, ListOfIdEndFace);
194 TopoDS_Shape S = myGeomGUI->GetShapeReader().GetShape(myGeom, aResult);
195 Standard_CString type;
196 myGeomBase->GetShapeTypeString(S,type);
197 aResult->NameType(type);
199 if(myGeomBase->Display(aResult))
200 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
202 catch(const SALOME::SALOME_Exception& S_ex) {
203 QtCatchCorbaException(S_ex);
209 //=====================================================================================
210 // function : OnSuppressHolesInFaceOrShell()
211 // purpose : To suppress one or more holes on a face
212 // : 'ListOfIdWires' contains indices or wires/holes.
213 //=====================================================================================
214 bool RepairGUI::OnSuppressHolesInFaceOrShell(const char* ShapeTopoIOR,
215 const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfIdWires)
217 /* Test the type of viewer */
218 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
222 GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(ShapeTopoIOR);
223 GEOM::GEOM_Shape_var aResult = myGeom->SuppressHolesInFaceOrShell(aShape, ListOfIdWires);
225 TopoDS_Shape S = myGeomGUI->GetShapeReader().GetShape(myGeom, aResult);
226 Standard_CString type;
227 myGeomBase->GetShapeTypeString(S,type);
228 aResult->NameType(type);
230 if(myGeomBase->Display(aResult))
231 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
233 catch(const SALOME::SALOME_Exception& S_ex) {
234 QtCatchCorbaException(S_ex);
240 //=====================================================================================
241 // function : OnSuppressFaces()
242 // purpose : To suppress faces from a shape
243 // : The result is one or more shells/faces as main shapes !
244 //=====================================================================================
245 bool RepairGUI::OnSuppressFaces(const TopoDS_Shape& ShapeTopo, const char* ShapeTopoIOR,
246 const Standard_Integer& aLocalContextId, bool& myUseLocalContext)
248 /* Test the type of viewer */
249 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
252 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
253 SALOMEDS::SObject_var theObj = aStudy->FindObjectIOR(ShapeTopoIOR);
254 if(theObj->_is_nil()) {
255 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY"));
259 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
260 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
262 if(myUseLocalContext == false) {
263 /* local context is from DialogBox */
264 MESSAGE("Error : No local context opened for suppress faces method" << endl);
268 GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID;
270 int nbSelected = ic->NbSelected();
271 ListOfID->length(nbSelected);
273 /* Create a list of indices of faces to be suppressed */
275 const int SubShapeType = 4; /* GEOM::FACE type */
276 ic->InitSelected(); /* to repositioning at beginning */
277 while(ic->MoreSelected()) {
278 int index = myGeomBase->GetIndex(ic->SelectedShape(), ShapeTopo, SubShapeType);
284 /* Close local context opened in DialogBox */
285 ic->CloseLocalContext(aLocalContextId);
286 myUseLocalContext = false;
288 /* Here is the main shape */
289 GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(ShapeTopoIOR);
290 GEOM::GEOM_Gen::ListOfGeomShapes_var listGeomShapes = new GEOM::GEOM_Gen::ListOfGeomShapes;
292 /* Call geom method that return a list of shells/faces as result of suppress */
294 listGeomShapes = myGeom->SuppressFaces(aShape, ListOfID);
296 catch(const SALOME::SALOME_Exception& S_ex) {
297 QtCatchCorbaException(S_ex);
300 /* Test list of shells/faces */
301 if(listGeomShapes->length() < 1) {
305 /* Loop on each object created */
306 for(int i=0; i<listGeomShapes->length(); i++) {
307 GEOM::GEOM_Shape_var aShellOrFace = listGeomShapes[i];
308 TopoDS_Shape S = myGeomGUI->GetShapeReader().GetShape(myGeom, aShellOrFace);
313 char* nameG = (char *)malloc(20);
314 Standard_CString Type;
315 if(myGeomBase->GetShapeTypeString(S, Type)) {
316 aShellOrFace->NameType(Type);
317 sprintf (nameG, "%s_%d", Type, myGeomGUI->myNbGeom++);
320 aShellOrFace->NameType(tr("GEOM_SHAPE"));
321 sprintf (nameG, "%s_%d", tr("GEOM_SHAPE").latin1(), myGeomGUI->myNbGeom++);
324 /* Display with name */
325 if(!myGeomBase->Display(aShellOrFace, nameG)) {
326 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
331 QAD_Application::getDesktop()->putInfo (tr("GEOM_PRP_READY"));
336 //=====================================================================================
338 //=====================================================================================
341 bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
342 {return RepairGUI::OnGUIEvent(theCommandID, parent);}