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 <BRepAdaptor_Surface.hxx>
44 #include <BRepAdaptor_Curve.hxx>
45 #include <GeomAbs_CurveType.hxx>
46 #include <GeomAbs_SurfaceType.hxx>
48 #include <TopoDS_Edge.hxx>
49 #include <TopoDS_Face.hxx>
51 #include "VTKViewer_RenderWindowInteractor.h"
52 #include "VTKViewer_ViewFrame.h"
54 #include "GEOM_Actor.h"
55 #include "GEOM_Client.hxx"
56 #include "GEOM_AISShape.hxx"
57 #include "GEOM_AssemblyBuilder.h"
58 #include "GEOM_InteractiveObject.hxx"
60 static GEOM_Client ShapeReader;
62 GEOM_Swig::GEOM_Swig()
64 // MESSAGE("Constructeur");
67 GEOM_Swig::~GEOM_Swig()
69 // MESSAGE("Destructeur");
72 void GEOM_Swig::createAndDisplayGO(const char* Entry)
74 // MESSAGE("createAndDisplayGO");
75 QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
76 SALOMEDS::Study_var aStudy = ActiveStudy->getStudyDocument();
77 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
79 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
80 GEOM::GEOM_Gen_var Geom = GEOM::GEOM_Gen::_narrow(comp);
82 Standard_CString Fatherior = "";
83 SALOMEDS::SComponent_var father = aStudy->FindComponent("GEOM");
84 aStudyBuilder->DefineComponentInstance( father, Geom );
85 father->ComponentIOR( Fatherior );
87 SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(ActiveStudy->getActiveStudyFrame()->entry());
89 SALOMEDS::SObject_var obj = aStudy->FindObjectID(Entry);
90 SALOMEDS::GenericAttribute_var anAttr;
91 SALOMEDS::AttributeName_var aName;
92 SALOMEDS::AttributeIOR_var anIOR;
94 if ( !obj->FindAttribute(anAttr, "AttributeIOR"))
96 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
97 GEOM::GEOM_Shape_var aShape = Geom->GetIORFromString(anIOR->Value());
98 TopoDS_Shape Shape = ShapeReader.GetShape(Geom,aShape);
100 if ( !obj->_is_nil() ) {
101 if (obj->FindAttribute(anAttr, "AttributeName")) {
102 aName = SALOMEDS::AttributeName::_narrow(anAttr);
104 QAD_Operation* op = new SALOMEGUI_ImportOperation( ActiveStudy );
107 SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
108 aStudyBuilder->Addreference(newObj1, obj);
109 // commit transaction
112 if ( ActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { // VTK
113 //vtkQGLRenderWindowInteractor* myRenderInter = ActiveStudy->getActiveStudyFrame()->getRightFrame()->getVTKView()->getRWInteractor();
114 VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)ActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
115 int themode = myRenderInter->GetDisplayMode();
117 vtkActorCollection* theActors =
118 GEOM_AssemblyBuilder::BuildActors(Shape,0,themode,Standard_True);
119 theActors->InitTraversal();
120 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
121 while(!(anActor==NULL)) {
122 GEOM_Actor* GActor = GEOM_Actor::SafeDownCast( anActor );
123 Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(anIOR->Value(),
126 IO->setEntry(obj->GetID());
128 GActor->setName( aName->Value() );
130 myRenderInter->Display(GActor);
131 anActor = (vtkActor*)theActors->GetNextActor();
133 myRenderInter->Update();
135 else if ( ActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) // OCC
137 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)ActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
138 // QAD_Viewer3d* v3d = ActiveStudy->getActiveStudyFrame()->getViewerOCC();
139 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
140 Handle(GEOM_AISShape) aSh = new GEOM_AISShape(Shape, aName->Value());
141 Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(anIOR->Value(),
145 IO->setEntry(obj->GetID());
147 aSh->setName( aName->Value() );
149 ic->AddOrRemoveCurrentObject(aSh, true);
153 ActiveStudy->updateObjBrowser( true );
156 int GEOM_Swig::getIndexTopology(const char* SubIOR, const char* IOR)
158 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
159 GEOM::GEOM_Gen_var Geom = GEOM::GEOM_Gen::_narrow(comp);
161 GEOM::GEOM_Shape_var aMainShape = Geom->GetIORFromString(IOR);
162 TopoDS_Shape shape = ShapeReader.GetShape(Geom, aMainShape);
164 GEOM::GEOM_Shape_var aSubShape = Geom->GetIORFromString(SubIOR);
165 TopoDS_Shape subshape = ShapeReader.GetShape(Geom, aSubShape);
167 TopExp_Explorer Exp ( shape, subshape.ShapeType() );
169 TopTools_MapOfShape M;
170 while ( Exp.More() ) {
171 if ( M.Add(Exp.Current()) ) {
172 if ( Exp.Current().IsSame(subshape) )
181 const char* GEOM_Swig::getShapeTypeString(const char* IOR)
183 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
184 GEOM::GEOM_Gen_var Geom = GEOM::GEOM_Gen::_narrow(comp);
186 GEOM::GEOM_Shape_var aShape = Geom->GetIORFromString(IOR);
187 TopoDS_Shape shape = ShapeReader.GetShape(Geom, aShape);
189 if( shape.IsNull() ) {
190 return "Null Shape" ;
193 switch (shape.ShapeType() )
195 case TopAbs_COMPOUND:
196 { return "Compound" ;}
197 case TopAbs_COMPSOLID:
198 { return "Compound Solid" ;}
205 BRepAdaptor_Surface surf(TopoDS::Face(shape));
206 if ( surf.GetType() == GeomAbs_Plane ) {
208 } else if ( surf.GetType() == GeomAbs_Cylinder ) {
209 return "Cylindrical Face" ;
210 } else if ( surf.GetType() == GeomAbs_Sphere ) {
211 return "Spherical Face" ;
212 } else if ( surf.GetType() == GeomAbs_Torus ) {
213 return "Toroidal Face" ;
214 } else if ( surf.GetType() == GeomAbs_Cone ) {
215 return "Conical Face" ;
217 return "GEOM::FACE" ;
224 BRepAdaptor_Curve curv(TopoDS::Edge(shape));
225 if ( curv.GetType() == GeomAbs_Line ) {
226 if ( (Abs(curv.FirstParameter()) >= 1E6 ) ||
227 (Abs(curv.LastParameter()) >= 1E6 )) {
231 } else if ( curv.GetType() == GeomAbs_Circle ) {
232 if ( curv.IsClosed() )
248 const char* GEOM_Swig::getShapeTypeIcon(const char* IOR)
250 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
251 GEOM::GEOM_Gen_var Geom = GEOM::GEOM_Gen::_narrow(comp);
253 GEOM::GEOM_Shape_var aShape = Geom->GetIORFromString(IOR);
255 if( aShape->_is_nil() ) {
259 switch (aShape->ShapeType() )
261 case TopAbs_COMPOUND:
262 { return "ICON_OBJBROWSER_COMPOUND" ;}
263 case TopAbs_COMPSOLID:
264 { return "ICON_OBJBROWSER_COMPSOLID" ;}
266 { return "ICON_OBJBROWSER_SOLID" ;}
268 { return "ICON_OBJBROWSER_SHELL" ;}
270 { return "ICON_OBJBROWSER_FACE" ;}
272 { return "ICON_OBJBROWSER_WIRE" ;}
274 { return "ICON_OBJBROWSER_EDGE" ;}
276 { return "ICON_OBJBROWSER_VERTEX" ;}
281 void GEOM_Swig::setDisplayMode(const char* Entry, int mode)
283 QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
284 Handle(SALOME_InteractiveObject) IO =
285 myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->FindIObject( Entry );
287 if ( myStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { // VTK
288 VTKViewer_RenderWindowInteractor* myRenderInter =
289 ((VTKViewer_ViewFrame*)myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
291 myRenderInter->SwitchRepresentation(IO, mode);
292 myRenderInter->Update();
294 else if ( myStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) // OCC
296 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
297 v3d->SwitchRepresentation(IO, mode);
301 void GEOM_Swig::setColor(const char* Entry, int red, int green, int blue)
303 QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
304 QColor c = QColor (red, green, blue);
305 Handle(SALOME_InteractiveObject) IO =
306 myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->FindIObject( Entry );
308 if ( myStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { // VTK
309 VTKViewer_RenderWindowInteractor* myRenderInter =
310 ((VTKViewer_ViewFrame*)myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
311 myRenderInter->SetColor(IO,c);
312 myRenderInter->Update();
314 else if ( myStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) // OCC
316 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
321 void GEOM_Swig::setTransparency(const char* Entry, float transp)
323 QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
324 Handle(SALOME_InteractiveObject) IO =
325 myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->FindIObject( Entry );
327 if ( myStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { // VTK
328 VTKViewer_RenderWindowInteractor* myRenderInter =
329 ((VTKViewer_ViewFrame*)myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
330 myRenderInter->SetTransparency(IO,transp);
331 myRenderInter->Update();
333 else if ( myStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) // OCC
335 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
336 v3d->SetTransparency(IO,transp);