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 "OCCViewer_ViewFrame.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 "SALOME_Event.hxx"
56 #include "VTKViewer_RenderWindowInteractor.h"
57 #include "VTKViewer_ViewFrame.h"
59 #include "GEOM_Actor.h"
60 #include "GEOM_Client.hxx"
61 #include "GEOM_AISShape.hxx"
62 #include "GEOM_AssemblyBuilder.h"
63 #include "GEOM_InteractiveObject.hxx"
65 #include "utilities.h"
69 static GEOM_Client ShapeReader;
72 template<class TViewFrame> inline TViewFrame* GetFrame(QAD_Study* theStudy){
73 return dynamic_cast<TViewFrame*>(SALOME::GetViewFrame(theStudy));
77 GEOM_Swig::GEOM_Swig()
79 // MESSAGE("Constructeur");
82 GEOM_Swig::~GEOM_Swig()
84 // MESSAGE("Destructeur");
87 void GEOM_Swig::createAndDisplayGO(const char* Entry)
89 // MESSAGE("createAndDisplayGO");
90 QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
91 SALOMEDS::Study_var aStudy = ActiveStudy->getStudyDocument();
92 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
94 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
95 GEOM::GEOM_Gen_var Geom = GEOM::GEOM_Gen::_narrow(comp);
97 CORBA::String_var aFatherIOR;
98 SALOMEDS::SComponent_var father = aStudy->FindComponent("GEOM");
99 aStudyBuilder->DefineComponentInstance( father, Geom );
100 father->ComponentIOR(aFatherIOR);
102 SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(ActiveStudy->getActiveStudyFrame()->entry());
104 SALOMEDS::SObject_var obj = aStudy->FindObjectID(Entry);
105 SALOMEDS::GenericAttribute_var anAttr;
106 SALOMEDS::AttributeIOR_var anIOR;
108 if ( !obj->FindAttribute(anAttr, "AttributeIOR"))
110 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
111 CORBA::String_var anIORValue = anIOR->Value();
113 GEOM::GEOM_Object_var aShape = Geom->GetIORFromString(anIORValue);
114 TopoDS_Shape Shape = ShapeReader.GetShape(Geom,aShape);
116 if ( !obj->_is_nil() ) {
117 if (obj->FindAttribute(anAttr, "AttributeName")) {
118 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
119 CORBA::String_var aNameValue = aName->Value();
121 QAD_Operation* op = new SALOMEGUI_ImportOperation( ActiveStudy );
124 SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
125 aStudyBuilder->Addreference(newObj1, obj);
126 // commit transaction
129 Handle(GEOM_InteractiveObject) anIO = new GEOM_InteractiveObject(const_cast<char*>(anIORValue.in()),
130 const_cast<char*>(aFatherIOR.in()),
132 const_cast<char*>(obj->GetID()));
134 class TEvent: public SALOME_Event{
136 TopoDS_Shape myShape;
137 Handle(SALOME_InteractiveObject) myIO;
140 TEvent(QAD_Study* theStudy, TopoDS_Shape theShape,
141 const Handle(SALOME_InteractiveObject)& theIO,
142 const char* theName):
143 myStudy(theStudy), myShape(theShape),
144 myIO(theIO), myName(theName)
146 virtual void Execute(){
147 if(VTKViewer_ViewFrame* aViewFrame = GetFrame<VTKViewer_ViewFrame>(myStudy)){
148 VTKViewer_RenderWindowInteractor* myRenderInter= aViewFrame->getRWInteractor();
149 int aMode = myRenderInter->GetDisplayMode();
151 vtkActorCollection* theActors = GEOM_AssemblyBuilder::BuildActors(myShape,0,aMode,true);
152 theActors->InitTraversal();
153 while(vtkActor* anActor = theActors->GetNextActor()){
154 GEOM_Actor* GActor = GEOM_Actor::SafeDownCast(anActor);
155 GActor->setName(const_cast<char*>(myName));
157 myRenderInter->Display(GActor);
159 myRenderInter->Update();
160 }else if(OCCViewer_ViewFrame* aViewFrame = GetFrame<OCCViewer_ViewFrame>(myStudy)){
161 Handle(AIS_InteractiveContext) ic = aViewFrame->getViewer()->getAISContext();
162 Handle(GEOM_AISShape) aSh = new GEOM_AISShape(myShape,const_cast<char*>(myName));
163 aSh->setName(const_cast<char*>(myName));
167 ic->AddOrRemoveCurrentObject(aSh,true);
169 myStudy->updateObjBrowser(true);
172 ProcessVoidEvent(new TEvent(ActiveStudy,Shape,anIO,aNameValue.in()));
178 int GEOM_Swig::getIndexTopology(const char* SubIOR, const char* IOR)
180 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
181 GEOM::GEOM_Gen_var Geom = GEOM::GEOM_Gen::_narrow(comp);
183 GEOM::GEOM_Object_var aMainShape = Geom->GetIORFromString(IOR);
184 TopoDS_Shape shape = ShapeReader.GetShape(Geom, aMainShape);
186 GEOM::GEOM_Object_var aSubShape = Geom->GetIORFromString(SubIOR);
187 TopoDS_Shape subshape = ShapeReader.GetShape(Geom, aSubShape);
190 if(subshape.ShapeType() == TopAbs_COMPOUND) {
192 TopTools_ListOfShape CL;
194 TopTools_ListIteratorOfListOfShape itC;
195 for(itC.Initialize(CL); itC.More(); itC.Next()) {
196 for(it.Initialize(itC.Value()); it.More(); it.Next()) {
197 if (it.Value().ShapeType() == TopAbs_COMPOUND) {
198 if (it.Value().IsSame(subshape))
202 CL.Append(it.Value());
208 TopExp_Explorer Exp(shape, subshape.ShapeType());
209 TopTools_MapOfShape M;
211 if(M.Add(Exp.Current())) {
212 if(Exp.Current().IsSame(subshape))
222 const char* GEOM_Swig::getShapeTypeString(const char* IOR)
224 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
225 GEOM::GEOM_Gen_var Geom = GEOM::GEOM_Gen::_narrow(comp);
227 GEOM::GEOM_Object_var aShape = Geom->GetIORFromString(IOR);
228 TopoDS_Shape shape = ShapeReader.GetShape(Geom, aShape);
230 if( shape.IsNull() ) {
231 return "Null Shape" ;
234 switch (shape.ShapeType() )
236 case TopAbs_COMPOUND:
237 { return "Compound" ;}
238 case TopAbs_COMPSOLID:
239 { return "Compound Solid" ;}
246 BRepAdaptor_Surface surf(TopoDS::Face(shape));
247 if ( surf.GetType() == GeomAbs_Plane ) {
249 } else if ( surf.GetType() == GeomAbs_Cylinder ) {
250 return "Cylindrical Face" ;
251 } else if ( surf.GetType() == GeomAbs_Sphere ) {
252 return "Spherical Face" ;
253 } else if ( surf.GetType() == GeomAbs_Torus ) {
254 return "Toroidal Face" ;
255 } else if ( surf.GetType() == GeomAbs_Cone ) {
256 return "Conical Face" ;
258 return "GEOM::FACE" ;
265 BRepAdaptor_Curve curv(TopoDS::Edge(shape));
266 if ( curv.GetType() == GeomAbs_Line ) {
267 if ( (Abs(curv.FirstParameter()) >= 1E6 ) ||
268 (Abs(curv.LastParameter()) >= 1E6 )) {
272 } else if ( curv.GetType() == GeomAbs_Circle ) {
273 if ( curv.IsClosed() )
290 const char* GEOM_Swig::getShapeTypeIcon(const char* IOR)
292 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
293 GEOM::GEOM_Gen_var Geom = GEOM::GEOM_Gen::_narrow(comp);
295 GEOM::GEOM_Object_var aShape = Geom->GetIORFromString(IOR);
296 TopoDS_Shape shape = ShapeReader.GetShape(Geom, aShape);
298 if( shape.IsNull() ) {
302 switch (shape.ShapeType() )
304 case TopAbs_COMPOUND:
305 { return "ICON_OBJBROWSER_COMPOUND" ;}
306 case TopAbs_COMPSOLID:
307 { return "ICON_OBJBROWSER_COMPSOLID" ;}
309 { return "ICON_OBJBROWSER_SOLID" ;}
311 { return "ICON_OBJBROWSER_SHELL" ;}
313 { return "ICON_OBJBROWSER_FACE" ;}
315 { return "ICON_OBJBROWSER_WIRE" ;}
317 { return "ICON_OBJBROWSER_EDGE" ;}
319 { return "ICON_OBJBROWSER_VERTEX" ;}
324 void GEOM_Swig::setDisplayMode(const char* theEntry, int theMode)
326 QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
327 Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject(aStudy,theEntry);
329 class TEvent: public SALOME_Event{
331 Handle(SALOME_InteractiveObject) myIO;
334 TEvent(QAD_Study* theStudy, const Handle(SALOME_InteractiveObject)& theIO, int theParam):
335 myStudy(theStudy), myIO(theIO), myParam(theParam)
337 virtual void Execute(){
338 if(VTKViewer_ViewFrame* aViewFrame = GetFrame<VTKViewer_ViewFrame>(myStudy)){
339 VTKViewer_RenderWindowInteractor* myRenderInter= aViewFrame->getRWInteractor();
340 myRenderInter->SetDisplayMode(myIO,myParam);
341 myRenderInter->Update();
342 }else if(OCCViewer_ViewFrame* aViewFrame = GetFrame<OCCViewer_ViewFrame>(myStudy)){
343 OCCViewer_Viewer3d* v3d = aViewFrame->getViewer();
344 v3d->SwitchRepresentation(myIO,myParam);
349 ProcessVoidEvent(new TEvent(aStudy,anIO,theMode));
352 void GEOM_Swig::setColor(const char* theEntry, int red, int green, int blue)
354 QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
355 Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject(aStudy,theEntry);
356 QColor aColor(red,green,blue);
358 class TEvent: public SALOME_Event{
360 Handle(SALOME_InteractiveObject) myIO;
363 TEvent(QAD_Study* theStudy, const Handle(SALOME_InteractiveObject)& theIO, const QColor& theParam):
364 myStudy(theStudy), myIO(theIO), myParam(theParam)
366 virtual void Execute(){
367 if(VTKViewer_ViewFrame* aViewFrame = GetFrame<VTKViewer_ViewFrame>(myStudy)){
368 VTKViewer_RenderWindowInteractor* myRenderInter= aViewFrame->getRWInteractor();
369 myRenderInter->SetColor(myIO,myParam);
370 myRenderInter->Update();
371 }else if(OCCViewer_ViewFrame* aViewFrame = GetFrame<OCCViewer_ViewFrame>(myStudy)){
372 OCCViewer_Viewer3d* v3d = aViewFrame->getViewer();
373 v3d->SetColor(myIO,myParam);
378 ProcessVoidEvent(new TEvent(aStudy,anIO,aColor));
381 void GEOM_Swig::setTransparency(const char* theEntry, float transp)
383 QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
384 Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject(aStudy,theEntry);
386 class TEvent: public SALOME_Event{
388 Handle(SALOME_InteractiveObject) myIO;
391 TEvent(QAD_Study* theStudy, const Handle(SALOME_InteractiveObject)& theIO, float theParam):
392 myStudy(theStudy), myIO(theIO), myParam(theParam)
394 virtual void Execute(){
395 if(VTKViewer_ViewFrame* aViewFrame = GetFrame<VTKViewer_ViewFrame>(myStudy)){
396 VTKViewer_RenderWindowInteractor* myRenderInter= aViewFrame->getRWInteractor();
397 myRenderInter->SetTransparency(myIO,myParam);
398 myRenderInter->Update();
399 }else if(OCCViewer_ViewFrame* aViewFrame = GetFrame<OCCViewer_ViewFrame>(myStudy)){
400 OCCViewer_Viewer3d* v3d = aViewFrame->getViewer();
401 v3d->SetTransparency(myIO,myParam);
406 ProcessVoidEvent(new TEvent(aStudy,anIO,transp));