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 : GeometryGUI_Swig.cxx
25 // Author : Nicolas REJNERI, Paul RASCLE
30 #include "GeometryGUI_Swig.hxx"
31 #include "utilities.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "QAD_Study.h"
36 #include "QAD_StudyFrame.h"
37 #include "QAD_RightFrame.h"
38 #include "SALOMEGUI_ImportOperation.h"
40 #include "OCCViewer_Viewer3d.h"
41 #include <TopExp_Explorer.hxx>
42 #include <TopTools_MapOfShape.hxx>
43 #include <TopTools_ListOfShape.hxx>
44 #include <TopTools_ListIteratorOfListOfShape.hxx>
45 #include <BRepAdaptor_Surface.hxx>
46 #include <BRepAdaptor_Curve.hxx>
47 #include <GeomAbs_CurveType.hxx>
48 #include <GeomAbs_SurfaceType.hxx>
50 #include <TopoDS_Edge.hxx>
51 #include <TopoDS_Face.hxx>
52 #include <TopoDS_Iterator.hxx>
54 #include "VTKViewer_RenderWindowInteractor.h"
55 #include "VTKViewer_ViewFrame.h"
57 #include "GEOM_Actor.h"
58 #include "GEOM_Client.hxx"
59 #include "GEOM_AISShape.hxx"
60 #include "GEOM_AssemblyBuilder.h"
61 #include "GEOM_InteractiveObject.hxx"
63 static GEOM_Client ShapeReader;
65 GEOM_Swig::GEOM_Swig()
67 // MESSAGE("Constructeur");
70 GEOM_Swig::~GEOM_Swig()
72 // MESSAGE("Destructeur");
75 void GEOM_Swig::createAndDisplayGO(const char* Entry)
77 // MESSAGE("createAndDisplayGO");
78 QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
79 SALOMEDS::Study_var aStudy = ActiveStudy->getStudyDocument();
80 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
82 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
83 GEOM::GEOM_Gen_var Geom = GEOM::GEOM_Gen::_narrow(comp);
85 Standard_CString Fatherior = "";
86 SALOMEDS::SComponent_var father = aStudy->FindComponent("GEOM");
87 aStudyBuilder->DefineComponentInstance( father, Geom );
88 father->ComponentIOR( Fatherior );
90 SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(ActiveStudy->getActiveStudyFrame()->entry());
92 SALOMEDS::SObject_var obj = aStudy->FindObjectID(Entry);
93 SALOMEDS::GenericAttribute_var anAttr;
94 SALOMEDS::AttributeName_var aName;
95 SALOMEDS::AttributeIOR_var anIOR;
97 if ( !obj->FindAttribute(anAttr, "AttributeIOR"))
99 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
100 GEOM::GEOM_Shape_var aShape = Geom->GetIORFromString(anIOR->Value());
101 TopoDS_Shape Shape = ShapeReader.GetShape(Geom,aShape);
103 if ( !obj->_is_nil() ) {
104 if (obj->FindAttribute(anAttr, "AttributeName")) {
105 aName = SALOMEDS::AttributeName::_narrow(anAttr);
107 QAD_Operation* op = new SALOMEGUI_ImportOperation( ActiveStudy );
110 SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
111 aStudyBuilder->Addreference(newObj1, obj);
112 // commit transaction
115 if ( ActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { // VTK
116 //vtkQGLRenderWindowInteractor* myRenderInter = ActiveStudy->getActiveStudyFrame()->getRightFrame()->getVTKView()->getRWInteractor();
117 VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)ActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
118 int themode = myRenderInter->GetDisplayMode();
120 vtkActorCollection* theActors =
121 GEOM_AssemblyBuilder::BuildActors(Shape,0,themode,Standard_True);
122 theActors->InitTraversal();
123 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
124 while(!(anActor==NULL)) {
125 GEOM_Actor* GActor = GEOM_Actor::SafeDownCast( anActor );
126 Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(anIOR->Value(),
129 IO->setEntry(obj->GetID());
131 GActor->setName( aName->Value() );
133 myRenderInter->Display(GActor);
134 anActor = (vtkActor*)theActors->GetNextActor();
136 myRenderInter->Update();
138 else if ( ActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) // OCC
140 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)ActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
141 // QAD_Viewer3d* v3d = ActiveStudy->getActiveStudyFrame()->getViewerOCC();
142 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
143 Handle(GEOM_AISShape) aSh = new GEOM_AISShape(Shape, aName->Value());
144 Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(anIOR->Value(),
148 IO->setEntry(obj->GetID());
150 aSh->setName( aName->Value() );
152 ic->AddOrRemoveCurrentObject(aSh, true);
156 ActiveStudy->updateObjBrowser( true );
159 int GEOM_Swig::getIndexTopology(const char* SubIOR, const char* IOR)
161 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
162 GEOM::GEOM_Gen_var Geom = GEOM::GEOM_Gen::_narrow(comp);
164 GEOM::GEOM_Shape_var aMainShape = Geom->GetIORFromString(IOR);
165 TopoDS_Shape shape = ShapeReader.GetShape(Geom, aMainShape);
167 GEOM::GEOM_Shape_var aSubShape = Geom->GetIORFromString(SubIOR);
168 TopoDS_Shape subshape = ShapeReader.GetShape(Geom, aSubShape);
171 if(subshape.ShapeType() == TopAbs_COMPOUND) {
173 TopTools_ListOfShape CL;
175 TopTools_ListIteratorOfListOfShape itC;
176 for(itC.Initialize(CL); itC.More(); itC.Next()) {
177 for(it.Initialize(itC.Value()); it.More(); it.Next()) {
178 if (it.Value().ShapeType() == TopAbs_COMPOUND) {
179 if (it.Value().IsSame(subshape))
183 CL.Append(it.Value());
189 TopExp_Explorer Exp(shape, subshape.ShapeType());
190 TopTools_MapOfShape M;
192 if(M.Add(Exp.Current())) {
193 if(Exp.Current().IsSame(subshape))
203 const char* GEOM_Swig::getShapeTypeString(const char* IOR)
205 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
206 GEOM::GEOM_Gen_var Geom = GEOM::GEOM_Gen::_narrow(comp);
208 GEOM::GEOM_Shape_var aShape = Geom->GetIORFromString(IOR);
209 TopoDS_Shape shape = ShapeReader.GetShape(Geom, aShape);
211 if( shape.IsNull() ) {
212 return "Null Shape" ;
215 switch (shape.ShapeType() )
217 case TopAbs_COMPOUND:
218 { return "Compound" ;}
219 case TopAbs_COMPSOLID:
220 { return "Compound Solid" ;}
227 BRepAdaptor_Surface surf(TopoDS::Face(shape));
228 if ( surf.GetType() == GeomAbs_Plane ) {
230 } else if ( surf.GetType() == GeomAbs_Cylinder ) {
231 return "Cylindrical Face" ;
232 } else if ( surf.GetType() == GeomAbs_Sphere ) {
233 return "Spherical Face" ;
234 } else if ( surf.GetType() == GeomAbs_Torus ) {
235 return "Toroidal Face" ;
236 } else if ( surf.GetType() == GeomAbs_Cone ) {
237 return "Conical Face" ;
239 return "GEOM::FACE" ;
246 BRepAdaptor_Curve curv(TopoDS::Edge(shape));
247 if ( curv.GetType() == GeomAbs_Line ) {
248 if ( (Abs(curv.FirstParameter()) >= 1E6 ) ||
249 (Abs(curv.LastParameter()) >= 1E6 )) {
253 } else if ( curv.GetType() == GeomAbs_Circle ) {
254 if ( curv.IsClosed() )
271 const char* GEOM_Swig::getShapeTypeIcon(const char* IOR)
273 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
274 GEOM::GEOM_Gen_var Geom = GEOM::GEOM_Gen::_narrow(comp);
276 GEOM::GEOM_Shape_var aShape = Geom->GetIORFromString(IOR);
278 if( aShape->_is_nil() ) {
282 switch (aShape->ShapeType() )
284 case TopAbs_COMPOUND:
285 { return "ICON_OBJBROWSER_COMPOUND" ;}
286 case TopAbs_COMPSOLID:
287 { return "ICON_OBJBROWSER_COMPSOLID" ;}
289 { return "ICON_OBJBROWSER_SOLID" ;}
291 { return "ICON_OBJBROWSER_SHELL" ;}
293 { return "ICON_OBJBROWSER_FACE" ;}
295 { return "ICON_OBJBROWSER_WIRE" ;}
297 { return "ICON_OBJBROWSER_EDGE" ;}
299 { return "ICON_OBJBROWSER_VERTEX" ;}
304 void GEOM_Swig::setDisplayMode(const char* Entry, int mode)
306 QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
307 Handle(SALOME_InteractiveObject) IO =
308 myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->FindIObject( Entry );
310 if ( myStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { // VTK
311 VTKViewer_RenderWindowInteractor* myRenderInter =
312 ((VTKViewer_ViewFrame*)myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
314 myRenderInter->SwitchRepresentation(IO, mode);
315 myRenderInter->Update();
317 else if ( myStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) // OCC
319 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
320 v3d->SwitchRepresentation(IO, mode);
324 void GEOM_Swig::setColor(const char* Entry, int red, int green, int blue)
326 QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
327 QColor c = QColor (red, green, blue);
328 Handle(SALOME_InteractiveObject) IO =
329 myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->FindIObject( Entry );
331 if ( myStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { // VTK
332 VTKViewer_RenderWindowInteractor* myRenderInter =
333 ((VTKViewer_ViewFrame*)myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
334 myRenderInter->SetColor(IO,c);
335 myRenderInter->Update();
337 else if ( myStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) // OCC
339 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
344 void GEOM_Swig::setTransparency(const char* Entry, float transp)
346 QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
347 Handle(SALOME_InteractiveObject) IO =
348 myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->FindIObject( Entry );
350 if ( myStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { // VTK
351 VTKViewer_RenderWindowInteractor* myRenderInter =
352 ((VTKViewer_ViewFrame*)myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
353 myRenderInter->SetTransparency(IO,transp);
354 myRenderInter->Update();
356 else if ( myStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) // OCC
358 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
359 v3d->SetTransparency(IO,transp);