Salome HOME
Merge from V6_main (04/10/2012)
[modules/geom.git] / src / GEOM_SWIG_WITHIHM / libGEOM_Swig.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : libGEOM_Swig.cxx
25 // Author : Nicolas REJNERI, Paul RASCLE
26 //
27 #include "libGEOM_Swig.h"
28
29 #include "GeometryGUI.h"
30 #include "GEOMToolsGUI.h"
31
32 #include "SUIT_Desktop.h"
33 #include "SUIT_Session.h"
34 #include "SalomeApp_Application.h"
35 #include "SalomeApp_Study.h"
36
37 #include "OB_Browser.h"
38
39 #include "OCCViewer_ViewWindow.h"
40 #include "OCCViewer_ViewManager.h"
41 #include "SOCC_ViewModel.h"
42 #include <SOCC_Prs.h>
43
44 #include "SVTK_ViewModel.h"
45 #include "SVTK_ViewWindow.h"
46 #include "SVTK_View.h"
47 #include "SVTK_Renderer.h"
48 #include <SVTK_Prs.h>
49
50 #include "GEOM_Actor.h"
51 #include "GEOM_Client.hxx"
52 #include "GEOM_AISShape.hxx"
53 #include "GEOM_InteractiveObject.hxx"
54 #include "GEOM_Displayer.h"
55 #include "GEOM_Constants.h"
56
57 #include "SALOME_Event.h"
58
59 // OCCT Includes
60 #include <TopAbs.hxx>
61 #include <TopoDS_Shape.hxx>
62 #include <AIS_ListOfInteractive.hxx>
63 #include <AIS_ListIteratorOfListOfInteractive.hxx>
64 #include <AIS_Drawer.hxx>
65 #include <Prs3d_IsoAspect.hxx>
66 #include <BRepTools.hxx>
67
68 // IDL Headers
69 #include <SALOMEconfig.h>
70 #include CORBA_SERVER_HEADER(GEOM_Gen)
71
72 #include <vtkRenderer.h>
73
74 static SHAPE_READER(ShapeReader);
75
76 inline OCCViewer_Viewer* GetOCCViewer(SUIT_Application* theApp){
77   SUIT_ViewWindow* window = theApp->desktop()->activeWindow();
78   if(window && window->getViewManager()->getType() == OCCViewer_Viewer::Type()){
79     OCCViewer_ViewWindow* vw = dynamic_cast<OCCViewer_ViewWindow*>( window );
80     if ( vw ) {
81       OCCViewer_ViewManager* vm = dynamic_cast<OCCViewer_ViewManager*>( vw->getViewManager() );
82       if ( vm )
83         return vm->getOCCViewer();
84     }
85   }
86
87   return 0;
88 }
89
90 inline SVTK_ViewWindow* GetSVTKViewWindow(SUIT_Application* theApp){
91   SUIT_ViewWindow* window = theApp->desktop()->activeWindow();
92   if(window && window->getViewManager()->getType() == SVTK_Viewer::Type())
93     return dynamic_cast<SVTK_ViewWindow*>( window );
94
95   return 0;
96 }
97
98 GEOM_Swig::GEOM_Swig()
99 {
100   // MESSAGE("Constructeur");
101 }
102
103 GEOM_Swig::~GEOM_Swig()
104 {
105   // MESSAGE("Destructeur");
106 }
107
108 void GEOM_Swig::createAndDisplayGO (const char* Entry, bool isUpdated)
109 {
110   class TEvent: public SALOME_Event
111   {
112     std::string myEntry;
113     bool        myUpdateViewer;
114   public:
115     TEvent(const char* theEntry, bool toUpdateViewer):
116       myEntry(theEntry),
117       myUpdateViewer(toUpdateViewer)
118     {}
119     virtual void Execute()
120     {
121       SUIT_Application* app = SUIT_Session::session()->activeApplication();
122       if (!app) return;
123
124       SalomeApp_Study* ActiveStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
125       if (!ActiveStudy) return;
126
127       _PTR(Study) aStudy(ActiveStudy->studyDS());
128       _PTR(StudyBuilder) aStudyBuilder = aStudy->NewBuilder();
129
130       GEOM::GEOM_Gen_var Geom = GeometryGUI::GetGeomGen();
131       if (CORBA::is_nil(Geom)) {
132         GeometryGUI::InitGeomGen();
133         Geom = GeometryGUI::GetGeomGen();
134       }
135       if (CORBA::is_nil(Geom))
136         return;
137
138       std::string aFatherIOR;
139       _PTR(SComponent) father = aStudy->FindComponent("GEOM");
140       if (!father)
141         return;
142       if (!father->ComponentIOR(aFatherIOR)) {
143         CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string(Geom);
144         aStudyBuilder->LoadWith(father, objStr.in());
145         father->ComponentIOR(aFatherIOR);
146       }
147
148       _PTR(SObject) obj = aStudy->FindObjectID(myEntry);
149       if (!obj)
150         return;
151
152       // Create new actor
153       _PTR(GenericAttribute) anAttr;
154       if (!obj->FindAttribute(anAttr, "AttributeIOR"))
155         return;
156       _PTR(AttributeIOR) anIOR(anAttr);
157       std::string anIORValue = anIOR->Value();
158
159       GEOM::GEOM_Object_var aShape = Geom->GetIORFromString(anIORValue.c_str());
160       TopoDS_Shape Shape = ShapeReader.GetShape(Geom,aShape);
161       if (!Shape.IsNull()) {
162         if (obj->FindAttribute(anAttr, "AttributeName")) {
163           _PTR(AttributeName) aName (anAttr);
164           std::string aNameValue = aName->Value();
165           // open transaction
166           /*SUIT_Operation* op = new SalomeApp_ImportOperation (app);
167           op->start();
168
169           _PTR(SObject) newObj1 = aStudyBuilder->NewObject(father);
170           aStudyBuilder->Addreference(newObj1, obj);
171           // commit transaction
172           op->commit();*/
173           Handle(GEOM_InteractiveObject) anIO =
174             new GEOM_InteractiveObject (const_cast<char*>(anIORValue.c_str()),
175                                         const_cast<char*>(aFatherIOR.c_str()),
176                                         "GEOM",
177                                         const_cast<char*>( obj->GetID().c_str()));
178
179           GEOM_Displayer(ActiveStudy).Display(anIO, myUpdateViewer);
180           /*if (SVTK_ViewWindow* aViewWindow = GetSVTKViewWindow(app)) {
181             SVTK_View* aView = aViewWindow->getView();
182             int aMode = aView->GetDisplayMode();
183
184             vtkActorCollection* theActors =
185               GEOM_AssemblyBuilder::BuildActors(Shape,0,aMode,true);
186             theActors->InitTraversal();
187             while (vtkActor* anActor = theActors->GetNextActor()) {
188               GEOM_Actor* GActor = GEOM_Actor::SafeDownCast(anActor);
189               GActor->setName(const_cast<char*>(aNameValue.c_str()));
190               GActor->setIO(anIO);
191               aView->Display(GActor);
192             }
193             aView->Repaint();
194           } else if (OCCViewer_Viewer* occViewer = GetOCCViewer(app)) {
195             Handle(AIS_InteractiveContext) ic = occViewer->getAISContext();
196             Handle(GEOM_AISShape) aSh =
197               new GEOM_AISShape (Shape,const_cast<char*>(aNameValue.c_str()));
198             aSh->setName(const_cast<char*>(aNameValue.c_str()));
199             aSh->setIO(anIO);
200             ic->Display(aSh);
201             ic->AddOrRemoveCurrentObject(aSh,true);
202             }*/
203           // update object browser
204           SalomeApp_Application* app = NULL; //dynamic_cast<SalomeApp_Application*>(app);
205           if (app) {
206             CAM_Module* module = app->module("Geometry");
207             SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>(module);
208             if (appMod)
209               appMod->updateObjBrowser(true);
210           }
211         }
212       }
213     }
214   };
215
216   // MESSAGE("createAndDisplayGO");
217   ProcessVoidEvent(new TEvent (Entry, isUpdated));
218
219   class TEventUpdateBrowser: public SALOME_Event
220     {
221       public:
222         TEventUpdateBrowser() {}
223         virtual void Execute() {
224           SalomeApp_Application* app =
225             dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
226           if (app) {
227             CAM_Module* module = app->module("Geometry");
228             SalomeApp_Module* appMod = dynamic_cast<SalomeApp_Module*>(module);
229             if (appMod) appMod->updateObjBrowser(true);
230           }
231         }
232     };
233
234   if (isUpdated)
235     ProcessVoidEvent(new TEventUpdateBrowser ());
236 }
237
238 void GEOM_Swig::createAndDisplayFitAllGO (const char* Entry)
239 {
240   class TEventFitAll: public SALOME_Event
241   {
242     public:
243       TEventFitAll() {}
244       virtual void Execute() {
245         SUIT_Application* app = SUIT_Session::session()->activeApplication();
246         if (!app) return;
247         
248         if (SVTK_ViewWindow* aViewWindow = GetSVTKViewWindow(app))
249           {
250             SVTK_View* aView = aViewWindow->getView();
251             aView->GetRenderer()->OnFitAll();
252           }
253         else if (OCCViewer_Viewer* occViewer = GetOCCViewer(app))
254           {  
255             Handle(V3d_Viewer) aViewer3d = occViewer->getViewer3d();
256             aViewer3d->InitActiveViews();
257             
258             if (aViewer3d->MoreActiveViews())
259               aViewer3d->ActiveView()->FitAll();
260           }
261       }
262   };
263
264   createAndDisplayGO(Entry);
265   ProcessVoidEvent(new TEventFitAll());
266 }
267
268 void GEOM_Swig::UpdateViewer()
269 {
270   class TEventUpdateViewer: public SALOME_Event
271   {
272     public:
273       TEventUpdateViewer() {}
274       virtual void Execute() {
275         SUIT_Application* app = SUIT_Session::session()->activeApplication();
276         if (!app) return;
277         SalomeApp_Study* ActiveStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
278         if (!ActiveStudy) return;
279         
280         GEOM_Displayer(ActiveStudy).UpdateViewer();
281       }
282   };
283   
284   ProcessVoidEvent(new TEventUpdateViewer());
285 }
286
287 int GEOM_Swig::getIndexTopology(const char* SubIOR, const char* IOR)
288 {
289   GEOM::GEOM_Gen_var aGeomGen = GeometryGUI::GetGeomGen();
290   if (CORBA::is_nil(aGeomGen))
291     return -1;
292
293   GEOM::GEOM_Object_var aMainShape = aGeomGen->GetIORFromString(IOR);
294   GEOM::GEOM_Object_var aSubShape  = aGeomGen->GetIORFromString(SubIOR);
295   if (CORBA::is_nil(aMainShape) || CORBA::is_nil(aSubShape))
296     return -1;
297
298   GEOM::GEOM_IShapesOperations_var anIShapesOperations =
299     aGeomGen->GetIShapesOperations(aMainShape->GetStudyID());
300   if (CORBA::is_nil(anIShapesOperations))
301     return -1;
302
303   return anIShapesOperations->GetTopologyIndex(aMainShape, aSubShape);
304 }
305
306 const char* GEOM_Swig::getShapeTypeString(const char* IOR)
307 {
308   TCollection_AsciiString aTypeName ("Shape of unknown type");
309
310   GEOM::GEOM_Gen_var aGeomGen = GeometryGUI::GetGeomGen();
311   if (!CORBA::is_nil(aGeomGen))
312   {
313     GEOM::GEOM_Object_var aShape = aGeomGen->GetIORFromString(IOR);
314     if (!CORBA::is_nil(aShape))
315     {
316       GEOM::GEOM_IShapesOperations_var anIShapesOperations =
317         aGeomGen->GetIShapesOperations(aShape->GetStudyID());
318       if (!CORBA::is_nil(anIShapesOperations))
319       {
320         aTypeName = anIShapesOperations->GetShapeTypeString(aShape);
321       }
322     }
323   }
324
325   return CORBA::string_dup(aTypeName.ToCString());
326 }
327
328
329 const char* GEOM_Swig::getShapeTypeIcon(const char* IOR)
330 {
331   GEOM::GEOM_Gen_var Geom = GeometryGUI::GetGeomGen();
332   if ( CORBA::is_nil( Geom ) )
333     return "None";
334
335   GEOM::GEOM_Object_var aShape = Geom->GetIORFromString(IOR);
336   TopoDS_Shape shape = ShapeReader.GetShape(Geom, aShape);
337
338   if( shape.IsNull() ) {
339     return "None" ;
340   }
341
342   switch (shape.ShapeType() )
343     {
344     case TopAbs_COMPOUND:
345       { return "ICON_OBJBROWSER_COMPOUND" ;}
346     case  TopAbs_COMPSOLID:
347       { return "ICON_OBJBROWSER_COMPSOLID" ;}
348     case TopAbs_SOLID:
349       { return "ICON_OBJBROWSER_SOLID" ;}
350     case TopAbs_SHELL:
351       { return "ICON_OBJBROWSER_SHELL" ;}
352     case TopAbs_FACE:
353       { return "ICON_OBJBROWSER_FACE" ;}
354     case TopAbs_WIRE:
355       { return "ICON_OBJBROWSER_WIRE" ;}
356     case TopAbs_EDGE:
357       { return "ICON_OBJBROWSER_EDGE" ;}
358     case TopAbs_VERTEX:
359       { return "ICON_OBJBROWSER_VERTEX" ;}
360     }
361
362   return "None";
363 }
364
365 void GEOM_Swig::setDisplayMode(const char* theEntry, int theMode, bool isUpdated)
366 {
367   class TEvent: public SALOME_Event {
368     std::string myEntry;
369     int myMode;
370     bool myUpdateViewer;
371   public:
372     TEvent(const char* theEntryArg, int theModeArg, bool theUpdated):
373       myEntry(theEntryArg), myMode(theModeArg), myUpdateViewer(theUpdated)
374     {}
375     virtual void Execute() {
376       SUIT_Application* anApp = SUIT_Session::session()->activeApplication();
377       if (!anApp) return;
378
379       Handle(SALOME_InteractiveObject) anIO =
380         new SALOME_InteractiveObject(myEntry.c_str(), "GEOM", "");
381
382       if (SVTK_ViewWindow* aViewWindow = GetSVTKViewWindow(anApp)) {
383         SVTK_View* aView = aViewWindow->getView();
384         aView->SetDisplayMode(anIO, myMode);
385         if (myUpdateViewer)
386           aView->Repaint();
387       }
388       else if (OCCViewer_Viewer* occViewer = GetOCCViewer(anApp)) {
389         SOCC_Viewer* soccViewer = dynamic_cast<SOCC_Viewer*>(occViewer);
390         if (soccViewer)
391           soccViewer->switchRepresentation(anIO, myMode, myUpdateViewer);
392       }
393     }
394   };
395
396   ProcessVoidEvent(new TEvent (theEntry, theMode, isUpdated));
397 }
398
399 void GEOM_Swig::setVectorsMode(const char* theEntry, bool isOn, bool isUpdated)
400 {
401   class TEvent: public SALOME_Event {
402     std::string myEntry;
403     bool myOn;
404     bool myUpdateViewer;
405   public:
406     TEvent(const char* theEntryArg, bool theOn, bool theUpdated):
407       myEntry(theEntryArg), myOn(theOn), myUpdateViewer(theUpdated)
408     {}
409     virtual void Execute() {
410       SUIT_Application* anApp = SUIT_Session::session()->activeApplication();
411       if (!anApp) return;
412
413       Handle(SALOME_InteractiveObject) anIO =
414         new SALOME_InteractiveObject(myEntry.c_str(), "GEOM", "");
415
416       if (SVTK_ViewWindow* aViewWindow = GetSVTKViewWindow(anApp)) {
417         SVTK_View* aView = aViewWindow->getView();
418         SVTK_Viewer* stvkViewer = dynamic_cast<SVTK_Viewer*>(aViewWindow->getViewManager()->getViewModel());
419         SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( stvkViewer->CreatePrs( myEntry.c_str()  ) );
420         vtkActorCollection* anActors = vtkPrs->GetObjects();
421         anActors->InitTraversal();
422         while (vtkActor* anAct = anActors->GetNextActor()) {
423           GEOM_Actor* aGeomActor = GEOM_Actor::SafeDownCast(anAct);
424           aGeomActor->SetVectorMode(!aGeomActor->GetVectorMode());
425         }
426         if (myUpdateViewer)
427           aView->Repaint();
428       }
429       else if (OCCViewer_Viewer* occViewer = GetOCCViewer(anApp)) {
430         Handle(AIS_InteractiveContext) ic = occViewer->getAISContext();
431         SOCC_Viewer* soccViewer = dynamic_cast<SOCC_Viewer*>(occViewer);
432         if (soccViewer) {
433           SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( soccViewer->CreatePrs( myEntry.c_str() ) );
434           if ( occPrs && !occPrs->IsNull() ) {
435             AIS_ListOfInteractive shapes; occPrs->GetObjects( shapes );
436             AIS_ListIteratorOfListOfInteractive interIter( shapes );
437             for ( ; interIter.More(); interIter.Next() ) {
438               Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( interIter.Value() );
439               aSh->SetDisplayVectors(myOn);
440               ic->RecomputePrsOnly(interIter.Value());
441             }
442           }
443         }
444       }
445     }
446   };
447
448   ProcessVoidEvent(new TEvent (theEntry, isOn, isUpdated));
449 }
450
451 void GEOM_Swig::setColor(const char* theEntry, int red, int green, int blue, bool isUpdated)
452 {
453   class TEvent: public SALOME_Event {
454     QString myEntry;
455     int myRed;
456     int myGreen;
457     int myBlue;
458     bool myUpdateViewer;
459   public:
460     TEvent(const char* theEntryArg, int theR, int theG, int theB, bool theUpdated):
461       myEntry(theEntryArg), myRed(theR), myGreen(theG), myBlue(theB), myUpdateViewer(theUpdated)
462     {}
463     virtual void Execute() {
464       SUIT_Application* anApp = SUIT_Session::session()->activeApplication();
465       if (!anApp) return;
466       GEOMToolsGUI::SetColor( myEntry, QColor( myRed, myGreen, myBlue), myUpdateViewer );
467     }
468   };
469   ProcessVoidEvent(new TEvent(theEntry, red, green, blue, isUpdated));
470 }
471
472 void GEOM_Swig::setIsos(const char* Entry, int nbU, int nbV, bool isUpdated )
473 {
474   class TEvent: public SALOME_Event {
475     std::string myEntry;
476     int myNbU, myNbV;
477     bool myUpdateViewer;
478   public:
479     TEvent(const char* theEntry, int theNbU, int theNbV, bool theUpdated):
480       myEntry(theEntry), myNbU(theNbU), myNbV(theNbV), myUpdateViewer(theUpdated)
481     {}
482     virtual void Execute() {
483       SUIT_Application* app = SUIT_Session::session()->activeApplication();
484       if (!app) return;
485       SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
486       if (!study) return;
487
488       Handle(SALOME_InteractiveObject) anIO =
489         new SALOME_InteractiveObject(myEntry.c_str(), "GEOM", "");
490
491       if (SVTK_ViewWindow* aViewWindow = GetSVTKViewWindow(app)) {
492         SVTK_Viewer* aView = dynamic_cast<SVTK_Viewer*>(aViewWindow->getViewManager()->getViewModel());
493         SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( aView->CreatePrs( myEntry.c_str() ) );
494         if ( vtkPrs ) {
495           vtkActorCollection* anActors = vtkPrs->GetObjects();
496           anActors->InitTraversal();
497           GEOM_Actor* anActor = GEOM_Actor::SafeDownCast( anActors->GetNextActor() );
498           if ( anActor ) {
499             int aIsos[2]={myNbU,myNbV};
500             anActor->SetNbIsos(aIsos);
501             anActor->StoreIsoNumbers();
502             QString anIsos = QString("%1%2%3").arg(myNbU).arg(DIGIT_SEPARATOR).arg(myNbV);
503             int aMgrId = aView->getViewManager()->getGlobalId();
504             study->setObjectProperty(aMgrId, myEntry.c_str(), ISOS_PROP, anIsos);
505           }
506         }
507         
508         if (myUpdateViewer)
509           aView->Repaint();
510       }
511       else if (OCCViewer_Viewer* occViewer = GetOCCViewer(app)) {
512         Handle(AIS_InteractiveContext) ic = occViewer->getAISContext();
513         SOCC_Viewer* soccViewer = dynamic_cast<SOCC_Viewer*>(occViewer);
514         if (soccViewer) {
515           int aMgrId = soccViewer->getViewManager()->getGlobalId();
516           SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( soccViewer->CreatePrs( myEntry.c_str() ) );
517           if ( occPrs && !occPrs->IsNull() ) {
518             AIS_ListOfInteractive shapes; occPrs->GetObjects( shapes );
519             AIS_ListIteratorOfListOfInteractive interIter( shapes );
520             for ( ; interIter.More(); interIter.Next() ) {
521               Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( interIter.Value() );
522               if ( !aSh.IsNull() ) {
523                 Handle(AIS_Drawer) drawer = aSh->Attributes();
524                 QVariant v = study->getObjectProperty( aMgrId, myEntry.c_str(), EDGE_WIDTH_PROP, QVariant() );
525                 int width = v.isValid() ? v.toInt() : 1;
526                 drawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, width, myNbU) );
527                 drawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, width, myNbV) );
528                 aSh->storeIsoNumbers();
529                 ic->SetLocalAttributes(aSh, drawer);
530                 ic->Redisplay(aSh);
531                 QString anIsos = QString("%1%2%3").arg(myNbU).arg(DIGIT_SEPARATOR).arg(myNbV);
532                 study->setObjectProperty(aMgrId, myEntry.c_str(), ISOS_PROP, anIsos);
533               }
534             }
535           }
536         }
537       }
538     }
539   };
540
541   ProcessVoidEvent(new TEvent (Entry, nbU, nbV, isUpdated));
542 }
543
544 void GEOM_Swig::setTransparency(const char* theEntry, float transp, bool isUpdated)
545 {
546   class TEvent: public SALOME_Event {
547     std::string myEntry;
548     float myParam;
549     bool myUpdateViewer;
550   public:
551     TEvent(const char* theEntryArg, float theParam, bool theUpdated):
552       myEntry(theEntryArg), myParam(theParam), myUpdateViewer(theUpdated)
553     {}
554     virtual void Execute() {
555       SUIT_Application* anApp = SUIT_Session::session()->activeApplication();
556       if (!anApp) return;
557
558       Handle(SALOME_InteractiveObject) anIO =
559         new SALOME_InteractiveObject(myEntry.c_str(), "GEOM", "");
560
561       if (SVTK_ViewWindow* aViewWindow = GetSVTKViewWindow(anApp)) {
562         SVTK_View* aView = aViewWindow->getView();
563         aView->SetTransparency(anIO, myParam);
564         if (myUpdateViewer)
565           aView->Repaint();
566       } else if (OCCViewer_Viewer* occViewer = GetOCCViewer(anApp)) {
567         SOCC_Viewer* soccViewer = dynamic_cast<SOCC_Viewer*>(occViewer);
568         if (soccViewer)
569           soccViewer->setTransparency(anIO, myParam, myUpdateViewer);
570       }
571     }
572   };
573
574   ProcessVoidEvent(new TEvent (theEntry, transp, isUpdated));
575 }
576
577
578 class TInitGeomGenEvent: public SALOME_Event {
579 public:
580   typedef bool TResult;
581   TResult myResult;
582   TInitGeomGenEvent() : myResult(false) {}
583   virtual void Execute() {
584     myResult = GeometryGUI::InitGeomGen();
585   }
586 };
587 bool GEOM_Swig::initGeomGen()
588 {
589   return ProcessEvent(new TInitGeomGenEvent());
590 }
591
592
593
594 void GEOM_Swig::eraseGO (const char* Entry, bool allWindows)
595 {
596   class TEvent: public SALOME_Event
597   {
598     std::string myEntry;
599     bool myFromAllWindows;
600   public:
601     TEvent(const char* theEntry, bool fromAllWindows):
602       myEntry(theEntry), myFromAllWindows(fromAllWindows)
603     {}
604     virtual void Execute()
605     {
606       SUIT_Application* app = SUIT_Session::session()->activeApplication();
607       if (!app) return;
608       SalomeApp_Study* ActiveStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
609       if (!ActiveStudy) return;
610
611       Handle (SALOME_InteractiveObject) aIO = new SALOME_InteractiveObject(myEntry.c_str(), "GEOM", "");
612
613       GEOM_Displayer(ActiveStudy).Erase(aIO, true);
614       /*      if (myFromAllWindows) {
615         QPtrList<SUIT_ViewWindow> aWindows = app->desktop()->windows();
616         SUIT_ViewWindow* aWin = 0;
617         for (aWin = aWindows.first(); aWin; aWin = aWindows.next()) {
618           EraseObject(aWin, aIO);
619         }
620       } else {
621         SUIT_ViewWindow* aWin = app->desktop()->activeWindow();
622         if (aWin)
623           EraseObject(aWin, aIO);
624           }*/
625     }
626
627     /*  private:
628     void EraseObject(SUIT_ViewWindow* theWin, Handle (SALOME_InteractiveObject) theIO)
629     {
630       if (theWin->getViewManager()->getType() == OCCViewer_Viewer::Type()){
631         OCCViewer_ViewWindow* vw = dynamic_cast<OCCViewer_ViewWindow*>( theWin );
632         if ( vw ) {
633           OCCViewer_ViewManager* vm = dynamic_cast<OCCViewer_ViewManager*>( vw->getViewManager() );
634           if ( vm ) {
635             SOCC_Viewer* aViewer = dynamic_cast<SOCC_Viewer*>(vm->getOCCViewer());
636             if (aViewer) {
637               SALOME_Prs* aPrs = aViewer->CreatePrs(myEntry.c_str());
638               if (aPrs) {
639                 SALOME_OCCPrs* aOccPrs =  dynamic_cast<SALOME_OCCPrs*>(aPrs);
640                 if (aOccPrs) {
641                   aViewer->Erase(aOccPrs);
642                   aViewer->Repaint();
643                 }
644               }
645             }
646           }
647         }
648       } else if (theWin->getViewManager()->getType() == SVTK_Viewer::Type()){
649         SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>( theWin );
650         if (aViewWindow) {
651           aViewWindow->Erase(theIO);
652         }
653       }
654       }*/
655
656   };
657   ProcessVoidEvent(new TEvent(Entry, allWindows));
658 }
659
660
661
662 void GEOM_Swig::setDeflection(const char* theEntry, float theDeflect)
663 {
664   class TEvent: public SALOME_Event {
665     std::string myEntry;
666     float myParam;
667   public:
668     TEvent(const char* theEntryArg, float theParam):
669       myEntry(theEntryArg), myParam(theParam)
670     {}
671     virtual void Execute() {
672       SUIT_Application* anApp = SUIT_Session::session()->activeApplication();
673       if (!anApp) return;
674
675       Handle(SALOME_InteractiveObject) anIO =
676         new SALOME_InteractiveObject(myEntry.c_str(), "GEOM", "");
677
678       if (SVTK_ViewWindow* aViewWindow = GetSVTKViewWindow(anApp)) {
679         vtkActorCollection* aActors = aViewWindow->getRenderer()->GetActors();
680         aActors->InitTraversal();
681         while (vtkActor* aAct = aActors->GetNextActor()) {
682           if (GEOM_Actor* aGeomActor = dynamic_cast<GEOM_Actor*>(aAct)) {
683             if (aGeomActor->hasIO()) {
684               Handle(SALOME_InteractiveObject) aNextIO = aGeomActor->getIO();
685               if (aNextIO->isSame(anIO)) {
686                 aGeomActor->setDeflection(myParam);
687                 aViewWindow->Repaint();
688                 return;
689               }
690             }
691           }
692         }
693         //      aView->SetTransparency(anIO, myParam);
694         //aView->Repaint();
695       } else if (OCCViewer_Viewer* occViewer = GetOCCViewer(anApp)) {
696         Handle(AIS_InteractiveContext) aContext = occViewer->getAISContext();
697         AIS_ListOfInteractive aAISList;
698         aContext->DisplayedObjects(aAISList);
699         AIS_ListIteratorOfListOfInteractive it(aAISList);
700         for (; it.More(); it.Next()) {
701           Handle(SALOME_InteractiveObject) aObj = 
702             Handle(SALOME_InteractiveObject)::DownCast(it.Value()->GetOwner());
703           if ((!aObj.IsNull()) && aObj->hasEntry() && aObj->isSame(anIO)) {
704             Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(it.Value());
705             if (!aShape.IsNull()) {
706               TopoDS_Shape aSh = aShape->Shape();
707               if (!aSh.IsNull())
708                 BRepTools::Clean(aSh);
709
710               aShape->SetOwnDeviationCoefficient( myParam );
711               aShape->SetOwnHLRDeviationAngle( 1.57 );
712               aContext->Redisplay(aShape);
713               return;
714             }
715           }
716         }
717       }
718     }
719   };
720
721   ProcessVoidEvent(new TEvent (theEntry, theDeflect));
722 }
723