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