]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMToolsGUI/GEOMToolsGUI_1.cxx
Salome HOME
GDD: Check that the PipeTShape is a block if it is required by user
[modules/geom.git] / src / GEOMToolsGUI / GEOMToolsGUI_1.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   : GEOMToolsGUI_1.cxx
25 //  Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
26 //
27 #include <PyConsole_Console.h>
28
29 #include "GEOMToolsGUI.h"
30 #include "GEOMToolsGUI_TransparencyDlg.h"
31 #include "GEOMToolsGUI_NbIsosDlg.h"
32 #include "GEOMToolsGUI_DeflectionDlg.h"
33 #include "GEOMToolsGUI_MarkerDlg.h"
34
35 #include <GeometryGUI.h>
36 #include <GEOM_Displayer.h>
37
38 #include <GEOMBase.h>
39 #include <GEOM_Actor.h>
40
41 #include <SALOME_ListIO.hxx>
42 #include <SALOME_ListIteratorOfListIO.hxx>
43
44 #include <SOCC_Prs.h>
45
46 #include <SVTK_Prs.h>
47 #include <SVTK_ViewModel.h>
48 #include <SVTK_ViewWindow.h>
49 #include <SVTK_View.h>
50
51 #include <OCCViewer_ViewModel.h>
52
53 #include <SUIT_ViewManager.h>
54 #include <SUIT_Desktop.h>
55 #include <SUIT_ResourceMgr.h>
56 #include <SUIT_Session.h>
57 #include <SUIT_OverrideCursor.h>
58 #include <SUIT_MessageBox.h>
59 #include <SUIT_Tools.h>
60
61 #include <SalomeApp_Application.h>
62 #include <SalomeApp_Study.h>
63 #include <SalomeApp_Module.h>
64
65 #include <LightApp_SelectionMgr.h>
66 #include <LightApp_NameDlg.h>
67
68 #include <GEOMImpl_Types.hxx>
69
70 #include "utilities.h"
71
72 // OCCT Includes
73 #include <AIS_Drawer.hxx>
74 #include <Prs3d_IsoAspect.hxx>
75 #include <Prs3d_PointAspect.hxx>
76 #include <Graphic3d_AspectMarker3d.hxx>
77 #include <Graphic3d_HArray1OfBytes.hxx>
78
79 // QT Includes
80 #include <QColorDialog>
81 #include <QInputDialog>
82 #include <QList>
83
84 #include <QGridLayout>
85 #include <QGroupBox>
86 #include <QSpinBox>
87 #include <QPushButton>
88 #include <QKeyEvent>
89
90 // VTK includes
91 #include <vtkRenderer.h>
92
93 void GEOMToolsGUI::OnRename()
94 {
95   SALOME_ListIO selected;
96   SalomeApp_Application* app =
97     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
98   if ( app ) {
99     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
100     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
101     if ( aSelMgr && appStudy ) {
102       aSelMgr->selectedObjects( selected );
103       if ( !selected.IsEmpty() ) {
104         _PTR(Study) aStudy = appStudy->studyDS();
105
106         bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
107         if ( aLocked ) {
108           SUIT_MessageBox::warning ( app->desktop(),
109                                      QObject::tr("WRN_WARNING"),
110                                      QObject::tr("WRN_STUDY_LOCKED") );
111           return;
112         }
113
114         bool isAny = false; // is there any appropriate object selected
115         for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
116           Handle(SALOME_InteractiveObject) IObject = It.Value();
117
118           _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
119           _PTR(GenericAttribute) anAttr;
120           if ( obj ) {
121             if ( obj->FindAttribute(anAttr, "AttributeName") ) {
122               _PTR(AttributeName) aName (anAttr);
123
124               GEOM::GEOM_Object_var anObj =
125                 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(obj));
126               if (!CORBA::is_nil(anObj)) {
127                 isAny = true;
128                 QString newName = LightApp_NameDlg::getName( app->desktop(), aName->Value().c_str() );
129                 if (!newName.isEmpty()) {
130                   aName->SetValue( newName.toLatin1().data() ); // rename the SObject
131                   IObject->setName( newName.toLatin1().data() );// rename the InteractiveObject
132                   anObj->SetName( newName.toLatin1().data() );  // Rename the corresponding GEOM_Object
133                   (dynamic_cast<SalomeApp_Module*>(app->activeModule()))->updateObjBrowser( false );
134                 }
135               } // if ( anObj )
136             } // if ( name attribute )
137           } // if ( obj )
138         } // iterator
139
140         if (!isAny) {
141           SUIT_MessageBox::warning( app->desktop(),
142                                     QObject::tr("WRN_WARNING"),
143                                     QObject::tr("GEOM_WRN_NO_APPROPRIATE_SELECTION") );
144           return;
145         }
146       }
147     }
148   }
149
150   app->updateActions(); //SRN: To update a Save button in the toolbar
151 }
152
153 void GEOMToolsGUI::OnCheckGeometry()
154 {
155   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
156   PyConsole_Console* pyConsole = app->pythonConsole();
157
158   if(pyConsole)
159     pyConsole->exec("from GEOM_usinggeom import *");
160 }
161
162 void GEOMToolsGUI::OnAutoColor()
163 {
164   SALOME_ListIO selected;
165   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
166   if( !app )
167     return;
168
169   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
170   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
171   if( !aSelMgr || !appStudy )
172     return;
173
174   aSelMgr->selectedObjects( selected );
175   if( selected.IsEmpty() )
176     return;
177
178   Handle(SALOME_InteractiveObject) anIObject = selected.First();
179
180   _PTR(Study) aStudy = appStudy->studyDS();
181   _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
182   GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
183   if( CORBA::is_nil( aMainObject ) )
184     return;
185
186   aMainObject->SetAutoColor( true );
187
188   QList<SALOMEDS::Color> aReservedColors;
189
190   GEOM_Displayer aDisp (appStudy);
191
192   SALOME_View* vf = aDisp.GetActiveView();
193
194   SUIT_ViewWindow* window = app->desktop()->activeWindow();
195   bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
196   bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
197
198   for( _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) ); it->More(); it->Next() )
199   {
200     _PTR(SObject) aChildSObject( it->Value() );
201     GEOM::GEOM_Object_var aChildObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
202     if( CORBA::is_nil( aChildObject ) )
203       continue;
204
205     if( aChildObject->GetType() != GEOM_GROUP )
206       continue;
207
208     SALOMEDS::Color aColor = GEOM_Displayer::getUniqueColor( aReservedColors );
209     aChildObject->SetColor( aColor );
210     aReservedColors.append( aColor );
211
212     QColor c( (int)( aColor.R * 255.0 ), (int)( aColor.G * 255.0 ), (int)( aColor.B * 255.0 ) );
213
214     SALOME_Prs* aPrs = vf->CreatePrs( aChildSObject->GetID().c_str() );
215
216     if ( isVTK )
217     {
218       SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
219       if ( !vtkVW )
220         return;
221       SVTK_View* aView = vtkVW->getView();
222       SUIT_OverrideCursor();
223       for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() )
224         aView->SetColor( It.Value(), c );
225     }
226     else if ( isOCC )
227     {
228       OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
229       Handle(AIS_InteractiveContext) ic = vm->getAISContext();
230
231       SOCC_Prs* anOCCPrs = dynamic_cast<SOCC_Prs*>( aPrs );
232       if( !anOCCPrs )
233         continue;
234
235       AIS_ListOfInteractive aList;
236       anOCCPrs->GetObjects( aList );
237       if( !aList.Extent() )
238         continue;
239
240       Handle(AIS_InteractiveObject) io = aList.First();
241       if( io.IsNull() )
242         continue;
243
244       Quantity_Color aQuanColor( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
245
246       // Set color for a point
247       Handle(AIS_Drawer) aCurDrawer = io->Attributes();
248       Handle(Prs3d_PointAspect) aCurPointAspect = aCurDrawer->PointAspect();
249       Quantity_Color aCurColor;
250       Standard_Real aCurScale;
251       Aspect_TypeOfMarker aCurTypeOfMarker;
252       aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
253       if ( aCurTypeOfMarker != Aspect_TOM_USERDEFINED ) {
254         aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aCurTypeOfMarker, aQuanColor, aCurScale) );
255       }
256       else {
257         Standard_Integer aWidth, aHeight;
258         aCurPointAspect->GetTextureSize( aWidth, aHeight );
259         Handle(Graphic3d_HArray1OfBytes) aTexture = aCurPointAspect->GetTexture();
260         aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aQuanColor, 1, aWidth, aHeight, aTexture ) );
261       }
262       ic->SetLocalAttributes( io, aCurDrawer );
263
264       io->SetColor( aQuanColor );
265       if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
266         Handle(GEOM_AISShape)::DownCast( io )->SetShadingColor( aQuanColor );
267
268       io->Redisplay( Standard_True );
269     }
270   }
271
272   app->updateActions(); //SRN: To update a Save button in the toolbar
273 }
274
275 void GEOMToolsGUI::OnDisableAutoColor()
276 {
277   SALOME_ListIO selected;
278   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
279   if( !app )
280     return;
281
282   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
283   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
284   if( !aSelMgr || !appStudy )
285     return;
286
287   aSelMgr->selectedObjects( selected );
288   if( selected.IsEmpty() )
289     return;
290
291   Handle(SALOME_InteractiveObject) anIObject = selected.First();
292
293   _PTR(Study) aStudy = appStudy->studyDS();
294   _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
295   GEOM::GEOM_Object_var aMainObject =  GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
296   if( CORBA::is_nil( aMainObject ) )
297     return;
298
299   aMainObject->SetAutoColor( false );
300
301 }
302
303 void GEOMToolsGUI::OnColor()
304 {
305   SALOME_ListIO selected;
306   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
307   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
308   if ( app && appStudy ) {
309     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
310     if ( aSelMgr ) {
311       aSelMgr->selectedObjects( selected );
312       if ( !selected.IsEmpty() ) {
313         SUIT_ViewWindow* window = app->desktop()->activeWindow();
314         bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
315         bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
316         if ( isVTK ) {
317           SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
318           if ( !vtkVW )
319             return;
320           SVTK_View* aView = vtkVW->getView();
321           QColor initcolor = aView->GetColor( selected.First()  );
322           QColor c = QColorDialog::getColor( initcolor, app->desktop() );
323           if ( c.isValid() ) {
324             SUIT_OverrideCursor();
325             for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
326               aView->SetColor( It.Value(), c );
327             }
328           }
329         } // if ( isVTK )
330         else if ( isOCC ) {
331           Handle(AIS_InteractiveObject) io = GEOMBase::GetAIS( selected.First() );
332           if ( !io.IsNull() ) {
333             Quantity_Color aColor;
334             io->Color( aColor );
335             QColor initcolor ((int)( aColor.Red() * 255.0 ),
336                               (int)( aColor.Green() * 255.0 ),
337                               (int)( aColor.Blue() * 255.0 ));
338             QColor c =  QColorDialog::getColor( initcolor, app->desktop() );
339             if ( c.isValid() ) {
340               SUIT_OverrideCursor();
341               aColor = Quantity_Color( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
342               for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
343                 io = GEOMBase::GetAIS( It.Value(), true );
344                 if ( !io.IsNull() ) {
345                   // Set color for a point
346                   OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>
347                     ( window->getViewManager()->getViewModel() );
348                   Handle (AIS_InteractiveContext) ic = vm->getAISContext();
349                   Handle(AIS_Drawer) aCurDrawer = io->Attributes();
350                   Handle(Prs3d_PointAspect) aCurPointAspect =  aCurDrawer->PointAspect();
351                   Quantity_Color aCurColor;
352                   Standard_Real aCurScale;
353                   Aspect_TypeOfMarker aCurTypeOfMarker;
354                   aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
355                   if ( aCurTypeOfMarker != Aspect_TOM_USERDEFINED ) {
356                     aCurDrawer->SetPointAspect(new Prs3d_PointAspect(aCurTypeOfMarker, aColor, aCurScale));
357                   }
358                   else {
359                     Standard_Integer aWidth, aHeight;
360                     aCurPointAspect->GetTextureSize( aWidth, aHeight );
361                     Handle(Graphic3d_HArray1OfBytes) aTexture = aCurPointAspect->GetTexture();
362                     aCurDrawer->SetPointAspect(new Prs3d_PointAspect(aColor, 1, aWidth, aHeight, aTexture));
363                   }
364                   ic->SetLocalAttributes(io, aCurDrawer);
365
366                   io->SetColor( aColor );
367                   if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
368                     Handle(GEOM_AISShape)::DownCast( io )->SetShadingColor( aColor );
369
370                   io->Redisplay( Standard_True );
371
372                   // store color to GEOM_Object
373                   _PTR(Study) aStudy = appStudy->studyDS();
374                   _PTR(SObject) aSObject( aStudy->FindObjectID( It.Value()->getEntry() ) );
375                   GEOM::GEOM_Object_var anObject =
376                     GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObject));
377
378                   SALOMEDS::Color aSColor;
379                   aSColor.R = (double)c.red() / 255.0;
380                   aSColor.G = (double)c.green() / 255.0;
381                   aSColor.B = (double)c.blue() / 255.0;
382                   anObject->SetColor( aSColor );
383                   anObject->SetAutoColor( false );
384                 }
385               }
386             } // if c.isValid()
387           } // first IO is not null
388         } // if ( isOCC )
389       } // if ( selection not empty )
390     }
391   }
392
393   app->updateActions(); //SRN: To update a Save button in the toolbar
394 }
395
396 void GEOMToolsGUI::OnTransparency()
397 {
398   GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
399   dlg.exec();
400 }
401
402 void GEOMToolsGUI::OnChangeTransparency( bool increase )
403 {
404  SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
405   if ( !app )
406     return;
407   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
408   if ( !aSelMgr )
409     return;
410   SALOME_ListIO selected;
411   aSelMgr->selectedObjects( selected );
412   if ( selected.IsEmpty() )
413     return;
414
415   Handle(SALOME_InteractiveObject) FirstIOS =  selected.First();
416   if ( FirstIOS.IsNull() )
417     return;
418
419   // Delta
420   float delta = 0.01;
421   if ( !increase )
422     delta *= -1;
423         
424   SUIT_ViewWindow* window = app->desktop()->activeWindow();
425   bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
426   bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
427
428   if ( isVTK ) {
429     SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
430     if ( !vtkVW )
431       return;
432     SVTK_View* aView = vtkVW->getView();
433    
434     float transp = aView->GetTransparency(FirstIOS);
435     
436     // Compute new transparency value
437     transp = transp + delta;
438     if ( transp < 0 )
439       transp = 0;
440     else if ( transp > 1 )
441       transp = 1;
442
443     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
444       aView->SetTransparency( It.Value(), transp );
445     }
446     aView->Repaint();
447   } // if ( isVTK )
448         
449   else if ( isOCC ) {
450     GEOMBase* gb = new GEOMBase();
451     Standard_Boolean found;
452     Handle(GEOM_AISShape) aisShape;
453    
454     aisShape = gb->ConvertIOinGEOMAISShape( FirstIOS, found );
455     if( !found )
456       return;
457     float transp = aisShape->Transparency();
458
459     // Compute new transparency value
460     transp = transp + delta;
461     if ( transp < 0 )
462       transp = 0;
463     else if ( transp > 1 )
464       transp = 1;
465
466     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
467     if ( !vm )
468       return;
469     Handle(AIS_InteractiveContext) ic = vm->getAISContext();
470     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
471       aisShape = gb->ConvertIOinGEOMAISShape( It.Value(), found );
472       if ( found ) {
473         ic->SetTransparency( aisShape, transp, false );
474         ic->Redisplay( aisShape, Standard_False, Standard_True );
475       }
476     } // for...
477     ic->UpdateCurrentViewer();
478   } // if ( isOCC )
479 }
480
481 void GEOMToolsGUI::OnNbIsos( ActionType actionType )
482 {
483   SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
484
485   bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
486   bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
487
488   if(isOCC){ // if is OCCViewer
489
490     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
491     Handle (AIS_InteractiveContext) ic = vm->getAISContext();
492
493     ic->InitCurrent();
494     if ( ic->MoreCurrent() ) {
495       Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
496       Handle(AIS_Drawer)    CurDrawer = CurObject->Attributes();
497
498       int UIso = CurDrawer->UIsoAspect()->Number();
499       int VIso = CurDrawer->VIsoAspect()->Number();
500
501       int newNbUIso = -1;
502       int newNbVIso = -1;
503
504       if ( actionType == SHOWDLG ) {
505         GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
506           new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
507
508         NbIsosDlg->setU( UIso );
509         NbIsosDlg->setV( VIso );
510
511         if ( NbIsosDlg->exec() ) {
512           SUIT_OverrideCursor();
513           
514           newNbUIso = NbIsosDlg->getU();
515           newNbVIso = NbIsosDlg->getV();
516         }
517       }
518       else if ( actionType == INCR || actionType == DECR ) {
519         int delta = 1;
520         if (actionType == DECR)
521           delta = -1;
522         
523         newNbUIso = UIso + delta;
524         newNbVIso = VIso + delta;
525
526         if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
527           return;
528       }
529
530       for(; ic->MoreCurrent(); ic->NextCurrent()) {
531         CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
532         Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
533         
534         CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , newNbUIso) );
535         CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , newNbVIso) );
536         
537         ic->SetLocalAttributes(CurObject, CurDrawer);
538         ic->Redisplay(CurObject);
539       }
540     }
541   }
542   else if(isVTK){ // if is VTKViewer
543     //
544     // Warning. It's works incorrect. must be recheked.
545     //
546     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >
547       ( SUIT_Session::session()->activeApplication() );
548     if ( !app )
549       return;
550     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
551     if ( !aSelMgr )
552       return;
553     SALOME_ListIO selected;
554     aSelMgr->selectedObjects( selected );
555     if ( selected.IsEmpty() )
556       return;
557
558     SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
559     if ( !vtkVW )
560       return;
561
562     SALOME_View* view = GEOM_Displayer::GetActiveView();
563
564     vtkActorCollection* aCollection = vtkActorCollection::New();
565
566     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
567       Handle(SALOME_InteractiveObject) anIObject = It.Value();
568       SALOME_Prs* aPrs = view->CreatePrs( anIObject->getEntry() );
569       SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( aPrs );
570       if ( vtkPrs ) {
571         vtkActorCollection* anActors = vtkPrs->GetObjects();
572         anActors->InitTraversal();
573         vtkActor* anAct = anActors->GetNextActor();
574         aCollection->AddItem(anAct);
575       }
576     }
577
578     if(aCollection)
579       aCollection->InitTraversal();
580     else
581       return;
582
583     int UIso = 0;
584     int VIso = 0;
585
586     vtkActor* anAct = aCollection->GetNextActor();
587     if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct))
588       anActor->GetNbIsos(UIso,VIso);
589     else
590       return;
591     
592     int newNbUIso = -1;
593     int newNbVIso = -1;
594
595     if ( actionType == SHOWDLG ) {
596       GEOMToolsGUI_NbIsosDlg* NbIsosDlg =
597         new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
598
599       NbIsosDlg->setU( UIso );
600       NbIsosDlg->setV( VIso );
601
602       if ( NbIsosDlg->exec() ) {
603         SUIT_OverrideCursor();
604
605         newNbUIso = NbIsosDlg->getU();
606         newNbVIso = NbIsosDlg->getV();
607       }
608     }
609     else if ( actionType == INCR || actionType == DECR ) {
610       int delta = 1;
611       if (actionType == DECR)
612         delta = -1;
613       
614       newNbUIso = UIso + delta;
615       newNbVIso = VIso + delta;
616       
617       if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
618         return;
619     } 
620     
621     while( anAct!=NULL ) {
622       if(GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)){
623         // There are no casting to needed actor.
624         int aIsos[2]={newNbUIso,newNbVIso};
625         anActor->SetNbIsos(aIsos);
626       }
627       anAct = aCollection->GetNextActor();
628     }
629     view->Repaint();
630   } // end vtkviewer
631 }
632
633 void GEOMToolsGUI::OnDeflection()
634 {
635   SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
636
637   bool isOCC = (window && window->getViewManager()->getType() == OCCViewer_Viewer::Type());
638   bool isVTK = (window && window->getViewManager()->getType() == SVTK_Viewer::Type());
639
640   if (isOCC) { // if is OCCViewer
641     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>(window->getViewManager()->getViewModel());
642     Handle (AIS_InteractiveContext) ic = vm->getAISContext();
643
644     ic->InitCurrent();
645     if (ic->MoreCurrent()) {
646       Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
647
648       Standard_Real aDC, aPrevDC;
649       Standard_Boolean isOwnDC = CurObject->OwnDeviationCoefficient(aDC, aPrevDC);
650       if (!isOwnDC)
651         aDC = ic->DeviationCoefficient();
652
653       GEOMToolsGUI_DeflectionDlg * DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
654         (SUIT_Session::session()->activeApplication()->desktop());
655       DeflectionDlg->setTheDC(aDC);
656       double aNewDC = 0.0;
657       bool ok = false;
658       while (!ok) {
659         if (DeflectionDlg->exec()) {
660           SUIT_OverrideCursor();
661           aNewDC = DeflectionDlg->getTheDC();
662           ok = (1e-07 <= aNewDC && aNewDC <= 1.0); // spinbox can return zero
663           if (ok) {
664             for (; ic->MoreCurrent(); ic->NextCurrent()) {
665               CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
666               ic->SetDeviationCoefficient(CurObject, aNewDC, Standard_True);
667               ic->Redisplay(CurObject);
668             }
669           }
670         }
671         else {
672           ok = true;
673         }
674       }
675     }
676   }
677   else if (isVTK) { // if is VTKViewer
678     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
679       (SUIT_Session::session()->activeApplication());
680     if (!app)
681       return;
682
683     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
684     if (!aSelMgr)
685       return;
686
687     SALOME_ListIO selected;
688     aSelMgr->selectedObjects(selected);
689     if (selected.IsEmpty())
690       return;
691
692     SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>(window);
693     if (!vtkVW)
694       return;
695
696     SALOME_View* view = GEOM_Displayer::GetActiveView();
697
698     vtkActorCollection* aCollection = vtkActorCollection::New();
699
700     for (SALOME_ListIteratorOfListIO It (selected); It.More(); It.Next()) {
701       Handle(SALOME_InteractiveObject) anIObject = It.Value();
702       SALOME_Prs* aPrs = view->CreatePrs(anIObject->getEntry());
703       SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>(aPrs);
704       if (vtkPrs) {
705         vtkActorCollection* anActors = vtkPrs->GetObjects();
706         anActors->InitTraversal();
707         vtkActor* anAct = anActors->GetNextActor();
708         aCollection->AddItem(anAct);
709       }
710     }
711
712     if (aCollection)
713       aCollection->InitTraversal();
714     else
715       return;
716
717     double aDC = 0.;
718
719     vtkActor* anAct = aCollection->GetNextActor();
720     if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct))
721       aDC = anActor->GetDeflection();
722     else
723       return;
724
725     GEOMToolsGUI_DeflectionDlg* DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
726       (SUIT_Session::session()->activeApplication()->desktop());
727     DeflectionDlg->setTheDC(aDC);
728     if (DeflectionDlg->exec()) {
729       SUIT_OverrideCursor();
730       aDC = DeflectionDlg->getTheDC();
731       while (anAct != NULL) {
732         if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
733           // There are no casting to needed actor.
734           bool isRel = anActor->GetIsRelative();
735           anActor->SetDeflection(aDC, isRel);
736         }
737         anAct = aCollection->GetNextActor();
738       }
739     }
740   } // end vtkviewer
741 }
742
743 void GEOMToolsGUI::OnSelectOnly(int mode)
744 {
745   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
746   if ( app ) {
747     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
748     GEOM_Displayer aDisp (appStudy);
749     aDisp.GlobalSelection(mode);
750     getGeometryGUI()->setLocalSelectionMode(mode);
751   }
752 }
753
754 void GEOMToolsGUI::OnShowHideChildren( bool show )
755 {
756   SALOME_ListIO selected;
757   SalomeApp_Application* app =
758     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
759   if ( app ) {
760     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
761     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
762     if ( aSelMgr && appStudy ) {
763       aSelMgr->selectedObjects( selected );
764       if ( !selected.IsEmpty() ) {
765         _PTR(Study) aStudy = appStudy->studyDS();
766         _PTR(StudyBuilder) B = aStudy->NewBuilder();
767
768         bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
769         if ( aLocked ) {
770           SUIT_MessageBox::warning( app->desktop(),
771                                     QObject::tr( "WRN_WARNING" ),
772                                     QObject::tr( "WRN_STUDY_LOCKED" ) );
773           return;
774         }
775
776         for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
777           Handle(SALOME_InteractiveObject) IObject = It.Value();
778
779           _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
780           _PTR(GenericAttribute) anAttr;
781           if ( obj ) {
782             _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
783             aExp->SetExpandable( show );
784           } // if ( obj )
785         } // iterator
786       }
787     }
788     app->updateObjectBrowser( false );
789     app->updateActions();
790   }
791 }
792
793 void GEOMToolsGUI::OnPointMarker()
794 {
795   GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
796   dlg.exec();
797 }