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
29 #include "GeometryGUI_Swig.hxx"
30 #include "SALOMEGUI_Swig.hxx"
32 #include "QAD_Application.h"
33 #include "QAD_Desktop.h"
34 #include "QAD_Study.h"
35 #include "QAD_StudyFrame.h"
36 #include "QAD_RightFrame.h"
37 #include "SALOMEGUI_ImportOperation.h"
39 #include "OCCViewer_Viewer3d.h"
40 #include <TopExp_Explorer.hxx>
41 #include <TopTools_MapOfShape.hxx>
42 #include <TopTools_ListOfShape.hxx>
43 #include <TopTools_ListIteratorOfListOfShape.hxx>
44 #include <BRepAdaptor_Surface.hxx>
45 #include <BRepAdaptor_Curve.hxx>
46 #include <GeomAbs_CurveType.hxx>
47 #include <GeomAbs_SurfaceType.hxx>
49 #include <TopoDS_Edge.hxx>
50 #include <TopoDS_Face.hxx>
51 #include <TopoDS_Iterator.hxx>
53 #include "SALOME_Event.hxx"
55 #include "VTKViewer_RenderWindowInteractor.h"
56 #include "VTKViewer_ViewFrame.h"
58 #include "GEOM_Actor.h"
59 #include "GEOM_Client.hxx"
60 #include "GEOM_AISShape.hxx"
61 #include "GEOM_AssemblyBuilder.h"
62 #include "GEOM_InteractiveObject.hxx"
64 #include "utilities.h"
68 static GEOM_Client ShapeReader;
71 template<class TViewFrame> inline TViewFrame* GetFrame(QAD_Study* theStudy){
72 return dynamic_cast<TViewFrame*>(SALOME::GetViewFrame(theStudy));
76 GEOM_Swig::GEOM_Swig()
78 // MESSAGE("Constructeur");
81 GEOM_Swig::~GEOM_Swig()
83 // MESSAGE("Destructeur");
86 void GEOM_Swig::createAndDisplayGO(const char* Entry)
88 // MESSAGE("createAndDisplayGO");
89 QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
90 SALOMEDS::Study_var aStudy = ActiveStudy->getStudyDocument();
91 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
93 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
94 GEOM::GEOM_Gen_var Geom = GEOM::GEOM_Gen::_narrow(comp);
96 CORBA::String_var aFatherIOR;
97 SALOMEDS::SComponent_var father = aStudy->FindComponent("GEOM");
98 aStudyBuilder->DefineComponentInstance( father, Geom );
99 father->ComponentIOR(aFatherIOR);
101 SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(ActiveStudy->getActiveStudyFrame()->entry());
103 SALOMEDS::SObject_var obj = aStudy->FindObjectID(Entry);
104 SALOMEDS::GenericAttribute_var anAttr;
105 SALOMEDS::AttributeIOR_var anIOR;
107 if ( !obj->FindAttribute(anAttr, "AttributeIOR"))
109 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
110 CORBA::String_var anIORValue = anIOR->Value();
112 GEOM::GEOM_Object_var aShape = Geom->GetIORFromString(anIORValue);
113 TopoDS_Shape Shape = ShapeReader.GetShape(Geom,aShape);
115 if ( !obj->_is_nil() ) {
116 if (obj->FindAttribute(anAttr, "AttributeName")) {
117 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
118 CORBA::String_var aNameValue = aName->Value();
120 QAD_Operation* op = new SALOMEGUI_ImportOperation( ActiveStudy );
123 SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
124 aStudyBuilder->Addreference(newObj1, obj);
125 // commit transaction
128 Handle(GEOM_InteractiveObject) anIO = new GEOM_InteractiveObject(const_cast<char*>(anIORValue.in()),
129 const_cast<char*>(aFatherIOR.in()),
131 const_cast<char*>(obj->GetID()));
133 class TEvent: public SALOME_Event{
135 TopoDS_Shape myShape;
136 Handle(SALOME_InteractiveObject) myIO;
139 TEvent(QAD_Study* theStudy, TopoDS_Shape theShape,
140 const Handle(SALOME_InteractiveObject)& theIO,
141 const char* theName):
142 myStudy(theStudy), myShape(theShape),
143 myIO(theIO), myName(theName)
145 virtual void Execute(){
146 if(VTKViewer_ViewFrame* aViewFrame = GetFrame<VTKViewer_ViewFrame>(myStudy)){
147 VTKViewer_RenderWindowInteractor* myRenderInter= aViewFrame->getRWInteractor();
148 int aMode = myRenderInter->GetDisplayMode();
150 vtkActorCollection* theActors = GEOM_AssemblyBuilder::BuildActors(myShape,0,aMode,true);
151 theActors->InitTraversal();
152 while(vtkActor* anActor = theActors->GetNextActor()){
153 GEOM_Actor* GActor = GEOM_Actor::SafeDownCast(anActor);
154 GActor->setName(const_cast<char*>(myName));
156 myRenderInter->Display(GActor);
158 myRenderInter->Update();
159 }else if(OCCViewer_ViewFrame* aViewFrame = GetFrame<OCCViewer_ViewFrame>(myStudy)){
160 Handle(AIS_InteractiveContext) ic = aViewFrame->getViewer()->getAISContext();
161 Handle(GEOM_AISShape) aSh = new GEOM_AISShape(myShape,const_cast<char*>(myName));
162 aSh->setName(const_cast<char*>(myName));
166 ic->AddOrRemoveCurrentObject(aSh,true);
168 myStudy->updateObjBrowser(true);
171 ProcessVoidEvent(new TEvent(ActiveStudy,Shape,anIO,aNameValue.in()));
177 int GEOM_Swig::getIndexTopology(const char* SubIOR, const char* IOR)
179 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
180 GEOM::GEOM_Gen_var Geom = GEOM::GEOM_Gen::_narrow(comp);
182 GEOM::GEOM_Object_var aMainShape = Geom->GetIORFromString(IOR);
183 TopoDS_Shape shape = ShapeReader.GetShape(Geom, aMainShape);
185 GEOM::GEOM_Object_var aSubShape = Geom->GetIORFromString(SubIOR);
186 TopoDS_Shape subshape = ShapeReader.GetShape(Geom, aSubShape);
189 if(subshape.ShapeType() == TopAbs_COMPOUND) {
191 TopTools_ListOfShape CL;
193 TopTools_ListIteratorOfListOfShape itC;
194 for(itC.Initialize(CL); itC.More(); itC.Next()) {
195 for(it.Initialize(itC.Value()); it.More(); it.Next()) {
196 if (it.Value().ShapeType() == TopAbs_COMPOUND) {
197 if (it.Value().IsSame(subshape))
201 CL.Append(it.Value());
207 TopExp_Explorer Exp(shape, subshape.ShapeType());
208 TopTools_MapOfShape M;
210 if(M.Add(Exp.Current())) {
211 if(Exp.Current().IsSame(subshape))
221 const char* GEOM_Swig::getShapeTypeString(const char* IOR)
223 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
224 GEOM::GEOM_Gen_var Geom = GEOM::GEOM_Gen::_narrow(comp);
226 GEOM::GEOM_Object_var aShape = Geom->GetIORFromString(IOR);
227 TopoDS_Shape shape = ShapeReader.GetShape(Geom, aShape);
229 if( shape.IsNull() ) {
230 return "Null Shape" ;
233 switch (shape.ShapeType() )
235 case TopAbs_COMPOUND:
236 { return "Compound" ;}
237 case TopAbs_COMPSOLID:
238 { return "Compound Solid" ;}
245 BRepAdaptor_Surface surf(TopoDS::Face(shape));
246 if ( surf.GetType() == GeomAbs_Plane ) {
248 } else if ( surf.GetType() == GeomAbs_Cylinder ) {
249 return "Cylindrical Face" ;
250 } else if ( surf.GetType() == GeomAbs_Sphere ) {
251 return "Spherical Face" ;
252 } else if ( surf.GetType() == GeomAbs_Torus ) {
253 return "Toroidal Face" ;
254 } else if ( surf.GetType() == GeomAbs_Cone ) {
255 return "Conical Face" ;
257 return "GEOM::FACE" ;
264 BRepAdaptor_Curve curv(TopoDS::Edge(shape));
265 if ( curv.GetType() == GeomAbs_Line ) {
266 if ( (Abs(curv.FirstParameter()) >= 1E6 ) ||
267 (Abs(curv.LastParameter()) >= 1E6 )) {
271 } else if ( curv.GetType() == GeomAbs_Circle ) {
272 if ( curv.IsClosed() )
289 const char* GEOM_Swig::getShapeTypeIcon(const char* IOR)
291 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
292 GEOM::GEOM_Gen_var Geom = GEOM::GEOM_Gen::_narrow(comp);
294 GEOM::GEOM_Object_var aShape = Geom->GetIORFromString(IOR);
295 TopoDS_Shape shape = ShapeReader.GetShape(Geom, aShape);
297 if( shape.IsNull() ) {
301 switch (shape.ShapeType() )
303 case TopAbs_COMPOUND:
304 { return "ICON_OBJBROWSER_COMPOUND" ;}
305 case TopAbs_COMPSOLID:
306 { return "ICON_OBJBROWSER_COMPSOLID" ;}
308 { return "ICON_OBJBROWSER_SOLID" ;}
310 { return "ICON_OBJBROWSER_SHELL" ;}
312 { return "ICON_OBJBROWSER_FACE" ;}
314 { return "ICON_OBJBROWSER_WIRE" ;}
316 { return "ICON_OBJBROWSER_EDGE" ;}
318 { return "ICON_OBJBROWSER_VERTEX" ;}
323 void GEOM_Swig::setDisplayMode(const char* theEntry, int theMode)
325 QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
326 Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject(aStudy,theEntry);
328 class TEvent: public SALOME_Event{
330 Handle(SALOME_InteractiveObject) myIO;
333 TEvent(QAD_Study* theStudy, const Handle(SALOME_InteractiveObject)& theIO, int theParam):
334 myStudy(theStudy), myIO(theIO), myParam(theParam)
336 virtual void Execute(){
337 if(VTKViewer_ViewFrame* aViewFrame = GetFrame<VTKViewer_ViewFrame>(myStudy)){
338 VTKViewer_RenderWindowInteractor* myRenderInter= aViewFrame->getRWInteractor();
339 myRenderInter->SetDisplayMode(myIO,myParam);
340 myRenderInter->Update();
341 }else if(OCCViewer_ViewFrame* aViewFrame = GetFrame<OCCViewer_ViewFrame>(myStudy)){
342 OCCViewer_Viewer3d* v3d = aViewFrame->getViewer();
343 v3d->SwitchRepresentation(myIO,myParam);
348 ProcessVoidEvent(new TEvent(aStudy,anIO,theMode));
351 void GEOM_Swig::setColor(const char* theEntry, int red, int green, int blue)
353 QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
354 Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject(aStudy,theEntry);
355 QColor aColor(red,green,blue);
357 class TEvent: public SALOME_Event{
359 Handle(SALOME_InteractiveObject) myIO;
362 TEvent(QAD_Study* theStudy, const Handle(SALOME_InteractiveObject)& theIO, const QColor& theParam):
363 myStudy(theStudy), myIO(theIO), myParam(theParam)
365 virtual void Execute(){
366 if(VTKViewer_ViewFrame* aViewFrame = GetFrame<VTKViewer_ViewFrame>(myStudy)){
367 VTKViewer_RenderWindowInteractor* myRenderInter= aViewFrame->getRWInteractor();
368 myRenderInter->SetColor(myIO,myParam);
369 myRenderInter->Update();
370 }else if(OCCViewer_ViewFrame* aViewFrame = GetFrame<OCCViewer_ViewFrame>(myStudy)){
371 OCCViewer_Viewer3d* v3d = aViewFrame->getViewer();
372 v3d->SetColor(myIO,myParam);
377 ProcessVoidEvent(new TEvent(aStudy,anIO,aColor));
380 void GEOM_Swig::setTransparency(const char* theEntry, float transp)
382 QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
383 Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject(aStudy,theEntry);
385 class TEvent: public SALOME_Event{
387 Handle(SALOME_InteractiveObject) myIO;
390 TEvent(QAD_Study* theStudy, const Handle(SALOME_InteractiveObject)& theIO, float theParam):
391 myStudy(theStudy), myIO(theIO), myParam(theParam)
393 virtual void Execute(){
394 if(VTKViewer_ViewFrame* aViewFrame = GetFrame<VTKViewer_ViewFrame>(myStudy)){
395 VTKViewer_RenderWindowInteractor* myRenderInter= aViewFrame->getRWInteractor();
396 myRenderInter->SetTransparency(myIO,myParam);
397 myRenderInter->Update();
398 }else if(OCCViewer_ViewFrame* aViewFrame = GetFrame<OCCViewer_ViewFrame>(myStudy)){
399 OCCViewer_Viewer3d* v3d = aViewFrame->getViewer();
400 v3d->SetTransparency(myIO,myParam);
405 ProcessVoidEvent(new TEvent(aStudy,anIO,transp));