]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMToolsGUI/GEOMToolsGUI_1.cxx
Salome HOME
*** empty log message ***
[modules/geom.git] / src / GEOMToolsGUI / GEOMToolsGUI_1.cxx
1 // GEOM GEOMGUI : GUI for Geometry component
2 //
3 // Copyright (C) 2004  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 // File   : GEOMToolsGUI_1.cxx
23 // Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
24 //
25
26 #include <PyConsole_Console.h>
27
28 #include "GEOMToolsGUI.h"
29
30 #include <GeometryGUI.h>
31 #include <GEOM_Displayer.h>
32 #include "GEOMToolsGUI_TransparencyDlg.h"
33 #include "GEOMToolsGUI_NbIsosDlg.h"        // Method ISOS adjustement
34
35 #include <GEOMBase.h>
36
37 #include <SALOME_ListIO.hxx>
38 #include <SALOME_ListIteratorOfListIO.hxx>
39
40 #include <SVTK_ViewModel.h>
41 #include <SVTK_ViewWindow.h>
42 #include <SVTK_View.h>
43
44 #include <OCCViewer_ViewModel.h>
45
46 #include <SUIT_ViewManager.h>
47 #include <SUIT_Desktop.h>
48 #include <SUIT_ResourceMgr.h>
49 #include <SUIT_Session.h>
50 #include <SUIT_OverrideCursor.h>
51 #include <SUIT_MessageBox.h>
52
53 #include <SalomeApp_Application.h>
54 #include <SalomeApp_Study.h>
55 #include <SalomeApp_Module.h>
56
57 #include <LightApp_SelectionMgr.h>
58 #include <LightApp_NameDlg.h>
59
60 #include "utilities.h"
61
62 // OCCT Includes
63 #include <AIS_Drawer.hxx>
64 #include <Prs3d_IsoAspect.hxx>
65 #include <Prs3d_PointAspect.hxx>
66 #include <Graphic3d_AspectMarker3d.hxx>
67
68 // QT Includes
69 #include <QColorDialog>
70
71 using namespace std;
72
73
74 void GEOMToolsGUI::OnSettingsColor()
75 {
76   SUIT_Session* sess = SUIT_Session::session();
77   SUIT_ResourceMgr* resMgr = sess->resourceMgr();
78   SUIT_Desktop* desk = sess->activeApplication()->desktop();
79
80   QColor anInitColor = resMgr->colorValue( "Geometry", "SettingsShadingColor", QColor( "yellow" ) );
81
82   QColor aDialogColor = QColorDialog::getColor(anInitColor, desk );
83   if( aDialogColor.isValid() )
84   {
85     QString type = desk->activeWindow()->getViewManager()->getType();
86     if( type != OCCViewer_Viewer::Type() && type != SVTK_Viewer::Type() )
87       MESSAGE("Settings Color is not supported for current Viewer");
88
89     resMgr->setValue( "Geometry", "SettingsShadingColor", aDialogColor );
90   }
91 }
92
93 void GEOMToolsGUI::OnSettingsIsos()
94 {
95 /*
96   SUIT_Session* sess = SUIT_Session::session();
97   SUIT_ResourceMgr* resMgr = sess->resourceMgr();
98   SUIT_Desktop* desk = sess->activeApplication()->desktop();
99
100   SUIT_ViewManager* vman = desk->activeWindow()->getViewManager();
101   QString type = vman->getType();
102
103   if ( type != OCCViewer_Viewer::Type() )
104     return;
105
106   OCCViewer_Viewer* vm = (OCCViewer_Viewer*)vman->getViewModel();
107   Handle (AIS_InteractiveContext) ic = vm->getAISContext();
108
109   int IsoU = resMgr->integerValue( "Geometry:SettingsIsoU", 1 );
110   int IsoV = resMgr->integerValue( "Geometry:SettingsIsoV", 1 );
111
112   ic->DefaultDrawer()->UIsoAspect()->SetNumber( IsoU );
113   ic->DefaultDrawer()->VIsoAspect()->SetNumber( IsoV );
114
115   GEOMBase_NbIsosDlg* NbIsosDlg = new GEOMBase_NbIsosDlg(desk, tr("GEOM_MEN_ISOS"), TRUE);
116
117   NbIsosDlg->SpinBoxU->setValue(IsoU);
118   NbIsosDlg->SpinBoxV->setValue(IsoV);
119
120   if(NbIsosDlg->exec()) {
121     IsoU = NbIsosDlg->SpinBoxU->text().toInt();
122     IsoV = NbIsosDlg->SpinBoxV->text().toInt();
123
124     ic->DefaultDrawer()->UIsoAspect()->SetNumber(UIso);
125     ic->DefaultDrawer()->VIsoAspect()->SetNumber(VIso);
126     resMgr->setValue("Geometry:SettingsIsoU", isoU);
127     resMgr->setValue("Geometry:SettingsIsoV", isoV);
128   }
129 */
130 }
131
132 void GEOMToolsGUI::OnSettingsStep()
133 {
134   SUIT_Session* sess = SUIT_Session::session();
135   SUIT_ResourceMgr* resMgr = sess->resourceMgr();
136
137   double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100. );
138
139   Standard_Boolean res = false;
140   double dd = GEOMBase::Parameter( res, QString("%1").arg(step).toLatin1().constData(), 
141                                    tr("GEOM_MEN_STEP_LABEL").toLatin1().constData(), 
142                                    tr("GEOM_STEP_TITLE").toLatin1().constData(), 0.001, 10000.0, 3);
143   if(res) {
144     resMgr->setValue( "Geometry", "SettingsGeomStep", dd );
145
146     /* Emit signal to GeometryGUI_SpinBoxes */
147     getGeometryGUI()->EmitSignalDefaultStepValueChanged( dd );
148   }
149   else
150     sess->activeApplication()->putInfo(tr("GEOM_PRP_ABORT"));
151 }
152
153 void GEOMToolsGUI::OnRename()
154 {
155   SALOME_ListIO selected;
156   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
157   if ( app ) {
158     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
159     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
160     if ( aSelMgr && appStudy ) {
161       aSelMgr->selectedObjects( selected );
162       if ( !selected.IsEmpty() ) {
163         _PTR(Study) aStudy = appStudy->studyDS();
164
165         bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
166         if ( aLocked ) {
167           SUIT_MessageBox::warning ( app->desktop(),
168                                      QObject::tr("WRN_WARNING"),
169                                      QObject::tr("WRN_STUDY_LOCKED"),
170                                      QObject::tr("BUT_OK") );
171           return;
172         }
173
174         for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
175           Handle(SALOME_InteractiveObject) IObject = It.Value();
176
177           _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
178           _PTR(GenericAttribute) anAttr;
179           if ( obj ) {
180             if( obj->FindAttribute(anAttr, "AttributeName") ) {
181               _PTR(AttributeName) aName (anAttr);
182
183               QString newName = LightApp_NameDlg::getName( app->desktop(), aName->Value().c_str() );
184               if ( !newName.isEmpty() ) {
185                 aName->SetValue( newName.toLatin1().constData() ); // rename the SObject
186                 IObject->setName( newName.toLatin1() );// rename the InteractiveObject
187                 // Rename the corresponding GEOM_Object
188                 GEOM::GEOM_Object_var anObj =  GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(obj));
189                 if (!CORBA::is_nil( anObj ))
190                   anObj->SetName( newName.toLatin1() );
191                 (dynamic_cast<SalomeApp_Module*>(app->activeModule()))->updateObjBrowser( false );
192               }
193             } // if ( name attribute )
194           } // if ( obj )
195         } // iterator
196       }
197     }
198   }
199   
200   app->updateActions(); //SRN: To update a Save button in the toolbar
201 }
202
203 void GEOMToolsGUI::OnCheckGeometry()
204 {
205   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
206   PyConsole_Console* pyConsole = app->pythonConsole();
207
208   if(pyConsole)
209     pyConsole->exec("from GEOM_usinggeom import *");
210 }
211
212 void GEOMToolsGUI::OnColor()
213 {
214   SALOME_ListIO selected;
215   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
216   if ( app ) {
217     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
218     if ( aSelMgr ) {
219       aSelMgr->selectedObjects( selected );
220       if ( !selected.IsEmpty() ) {
221         SUIT_ViewWindow* window = app->desktop()->activeWindow();
222         bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
223         bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
224         if ( isVTK ) {
225           SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
226           if ( !vtkVW )
227             return;
228           SVTK_View* aView = vtkVW->getView();
229           QColor initcolor = aView->GetColor( selected.First()  );
230           QColor c = QColorDialog::getColor( QColor(), app->desktop() );
231           if ( c.isValid() ) {
232             SUIT_OverrideCursor();
233             for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
234               aView->SetColor( It.Value(), c );
235             }
236           }
237         } // if ( isVTK )
238         else if ( isOCC ) {
239           Handle(AIS_InteractiveObject) io = GEOMBase::GetAIS( selected.First() );
240           if ( !io.IsNull() ) {
241             Quantity_Color aColor;
242             io->Color( aColor );
243             QColor initcolor( (int)( aColor.Red() * 255.0 ), (int)( aColor.Green() * 255.0 ), (int)( aColor.Blue() * 255.0 ) );
244             QColor c =  QColorDialog::getColor( initcolor, app->desktop() );
245             if ( c.isValid() ) {
246               SUIT_OverrideCursor();
247               aColor = Quantity_Color( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
248               for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
249                 io = GEOMBase::GetAIS( It.Value(), true );
250                 if ( !io.IsNull() ) {
251                   // Set color for a point
252                   OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
253                   Handle (AIS_InteractiveContext) ic = vm->getAISContext();
254                   Handle(AIS_Drawer) aCurDrawer = io->Attributes();
255                   Handle(Prs3d_PointAspect) aCurPointAspect =  aCurDrawer->PointAspect();
256                   Quantity_Color aCurColor;
257                   Standard_Real aCurScale;
258                   Aspect_TypeOfMarker aCurTypeOfMarker;
259                   aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
260                   aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aCurTypeOfMarker, aColor, aCurScale) );
261                   ic->SetLocalAttributes(io, aCurDrawer);
262                   
263                   io->SetColor( aColor );
264                   if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
265                     Handle(GEOM_AISShape)::DownCast( io )->SetShadingColor( aColor );
266
267                   io->Redisplay( Standard_True );
268                 }
269               }
270             } // if c.isValid()
271           } // first IO is not null
272         } // if ( isOCC )
273       } // if ( selection not empty )
274     }
275   }
276   
277   app->updateActions(); //SRN: To update a Save button in the toolbar
278 }
279
280 void GEOMToolsGUI::OnTransparency()
281 {
282   GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
283   dlg.exec();
284 }
285
286 void GEOMToolsGUI::OnNbIsos()
287 {
288   SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
289   bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
290
291   if ( !isOCC )
292     return;
293
294   OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
295   Handle (AIS_InteractiveContext) ic = vm->getAISContext();
296
297   ic->InitCurrent();
298   if ( ic->MoreCurrent() ) {
299     Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
300     Handle(AIS_Drawer)    CurDrawer = CurObject->Attributes();
301
302     int UIso = CurDrawer->UIsoAspect()->Number();
303     int VIso = CurDrawer->VIsoAspect()->Number();
304
305     GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
306       new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
307
308     NbIsosDlg->setU( UIso );
309     NbIsosDlg->setV( VIso );
310
311     if ( NbIsosDlg->exec() ) {
312       SUIT_OverrideCursor();
313       for(; ic->MoreCurrent(); ic->NextCurrent()) {
314         CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
315         Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
316
317         int nbUIso = NbIsosDlg->getU();
318         int nbVIso = NbIsosDlg->getV();
319
320         CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbUIso) );
321         CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbVIso) );
322
323         ic->SetLocalAttributes(CurObject, CurDrawer);
324         ic->Redisplay(CurObject);
325       }
326     }
327   }
328 }
329
330 void GEOMToolsGUI::OnOpen()
331 {
332 /*
333   SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
334   _PTR(Study) aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
335
336   SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
337   Handle(SALOME_InteractiveObject) anIObject;
338   for(;It.More();It.Next()) {
339     anIObject = It.Value();
340     _PTR(SObject) obj ( aStudy->FindObjectID(anIObject->getEntry()) );
341     _PTR(AttributePersistentRef) aPersist;
342     _PTR(AttributeIOR) anIOR;
343     if(obj) {
344       // this SObject may be GEOM module root SObject
345       _PTR(ChildIterator) anIter ( aStudy->NewChildIterator() );
346       _PTR(GenericAttribute) anAttr;
347       bool useSubItems = false;
348       while (anIter->More() && !useSubItems) {
349         _PTR(SObject) subobj ( anIter->Value() );
350         if (subobj->FindAttribute(anAttr, "AttributePersistentRef")) {
351           useSubItems = true;
352           obj =  subobj;
353         }
354         else
355           anIter->Next();
356       }
357       obj->FindAttribute(anAttr, "AttributePersistentRef");
358
359       while(useSubItems?anIter->More():!anAttr->_is_nil()) {
360         if(!obj->FindAttribute(anAttr, "AttributeIOR") &&
361            obj->FindAttribute(anAttr, "AttributePersistentRef")) {
362           _PTR(SComponent) FComp ( obj->GetFatherComponent() );
363           if (FComp) {
364             if (FComp->FindAttribute(anAttr, "AttributeName")) {
365               _PTR(AttributeName) aName ( anAttr );
366               QString compName = QAD_Application::getDesktop()->getComponentName(aName->Value().c_str());
367               //                    parent->loadComponentData(parent->getComponentName(aName->Value()));
368               Engines::Component_var comp ;
369               if ( compName.compare("SUPERV") == 0 ) {
370                 comp = QAD_Application::getDesktop()->getEngine( "SuperVisionContainer", compName) ;
371               }
372               else {
373                 comp = QAD_Application::getDesktop()->getEngine( "FactoryServer", compName);
374                 if ( comp->_is_nil() )
375                   comp = QAD_Application::getDesktop()->getEngine( "FactoryServerPy", compName);
376               }
377
378               if (!CORBA::is_nil(comp)) {
379                 SALOMEDS::Driver_var   driver = SALOMEDS::Driver::_narrow(comp);
380                 if (!CORBA::is_nil(driver)) {
381                   SALOMEDS::StudyBuilder_var  B = dynamic_cast<SALOMEDS_Study*>(aStudy.get())->GetStudy()->NewBuilder();
382                   if (!CORBA::is_nil(B)) {
383                     B->LoadWith(FComp,driver);
384                   } else {
385                     return;
386                   }
387                 }
388                 else {
389                   MESSAGE("loadComponentData(): Driver is null");
390                   return;
391                 }
392               }
393               else {
394                 MESSAGE("loadComponentData(): Engine is null");
395                 return;
396               }
397                 //              // load
398                 //              Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer","GEOM");
399                 //              if (!CORBA::is_nil(comp)) {
400                 //                SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
401                 //                SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
402                 //                SALOMEDS::SComponent_var SC = aStudy->FindComponent("GEOM");
403                 //                if (!CORBA::is_nil(SC))
404                 //                  aStudyBuilder->LoadWith(SC,driver);
405             }
406           }
407           else {
408             MESSAGE("Component is null");
409           }
410         }
411         if(useSubItems) {
412           anIter->Next();
413           obj.reset( anIter->Value() );
414         }
415         else
416           anAttr = NULL;
417       }
418     }
419   }
420 */
421 }
422
423 void GEOMToolsGUI::OnSelectOnly(int mode)
424 {
425   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
426   if ( app ) {
427     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
428     GEOM_Displayer aDisp (appStudy);
429     aDisp.GlobalSelection(mode);
430     getGeometryGUI()->setLocalSelectionMode(mode);
431   }
432 }