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