Salome HOME
Merge V8_4_BR branch.
[modules/geom.git] / src / GEOMGUI / GeometryGUI.cxx
1 // Copyright (C) 2007-2016  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, or (at your option) any later version.
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   : GeometryGUI.cxx
23 //  Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
24
25 #include <Standard_math.hxx>  // E.A. must be included before Python.h to fix compilation on windows
26 #ifdef HAVE_FINITE
27 #undef HAVE_FINITE            // VSR: avoid compilation warning on Linux : "HAVE_FINITE" redefined
28 #endif
29 #include "Python.h"
30 #include "GeometryGUI.h"
31 #include "GeometryGUI_Operations.h"
32 #include "GEOMPluginGUI.h"
33 #include "GEOMGUI_OCCSelector.h"
34 #include "GEOMGUI_Selection.h"
35 #include "GEOMGUI_CreationInfoWdg.h"
36 #include "GEOMGUI_TextTreeWdg.h"
37 #include "GEOMGUI_DimensionProperty.h"
38 #include "GEOM_Constants.h"
39 #include "GEOM_Displayer.h"
40 #include "GEOM_AISShape.hxx"
41 #include "GEOMUtils_XmlHandler.hxx"
42 #include "GEOMGUI_AnnotationMgr.h"
43 #include "GEOMGUI_TextTreeSelector.h"
44
45 #include "GEOM_Actor.h"
46
47 #include <Material_ResourceMgr.h>
48 #include <Material_Model.h>
49
50 #include <SUIT_Desktop.h>
51 #include <SUIT_MessageBox.h>
52 #include <SUIT_ResourceMgr.h>
53 #include <SUIT_Session.h>
54 #include <SUIT_ViewManager.h>
55
56 #include <OCCViewer_ViewWindow.h>
57 #include <OCCViewer_ViewPort3d.h>
58 #include <OCCViewer_ViewModel.h>
59 #include <OCCViewer_ViewManager.h>
60
61 #include <SOCC_ViewModel.h>
62 #include <SOCC_ViewWindow.h>
63
64 #include <SVTK_ViewWindow.h>
65 #include <SVTK_RenderWindowInteractor.h>
66 #include <SVTK_InteractorStyle.h>
67 #include <SVTK_ViewModel.h>
68
69 #ifndef DISABLE_GRAPHICSVIEW
70 #include <GraphicsView_Viewer.h>
71 #endif
72
73 #include <SalomeApp_Application.h>
74 #include <SalomeApp_DataObject.h>
75 #include <SalomeApp_Study.h>
76 #include <SalomeApp_Tools.h>
77
78 #include <LightApp_SelectionMgr.h>
79 #include <LightApp_VTKSelector.h>
80 #include <LightApp_DataObject.h>
81 #include <LightApp_Preferences.h>
82
83 #include <SALOME_LifeCycleCORBA.hxx>
84 #include <SALOME_ListIO.hxx>
85
86 #include <SALOMEDSClient_ClientFactory.hxx>
87 #include <SALOMEDSClient_IParameters.hxx>
88
89 #include <SALOMEDS_SObject.hxx>
90
91 #include <QtxFontEdit.h>
92
93 // External includes
94 #include <QDir>
95 #include <QSet>
96 #include <QMenu>
97 #include <QTime>
98 #include <QAction>
99 #include <QFileInfo>
100 #include <QString>
101 #include <QPainter>
102 #include <QSignalMapper>
103 #include <QFontDatabase>
104
105 #include <AIS_ListOfInteractive.hxx>
106 #include <AIS_ListIteratorOfListOfInteractive.hxx>
107 #include <Prs3d_Drawer.hxx>
108 #include <Prs3d_IsoAspect.hxx>
109 #include <Aspect_TypeOfMarker.hxx>
110 #include <OSD_SharedLibrary.hxx>
111 #include <NCollection_DataMap.hxx>
112
113 #include <TColStd_HArray1OfByte.hxx>
114 #include <TColStd_SequenceOfHAsciiString.hxx>
115
116 #include <utilities.h>
117
118 #include <vtkCamera.h>
119 #include <vtkRenderer.h>
120
121 #include <Standard_Failure.hxx>
122 #include <Standard_ErrorHandler.hxx>
123
124 #include <Font_SystemFont.hxx>
125 #include <Font_FontMgr.hxx>
126 #include <TCollection_HAsciiString.hxx>
127
128 #include "GEOM_version.h"
129 #include "GEOMImpl_Types.hxx" // dangerous hxx (defines short-name macros) - include after all
130
131 extern "C" {
132   Standard_EXPORT CAM_Module* createModule() {
133     return new GeometryGUI();
134   }
135
136   Standard_EXPORT char* getModuleVersion() {
137     return (char*)GEOM_VERSION_STR;
138   }
139 }
140
141 GeometryGUI::StudyTextureMap GeometryGUI::myTextureMap;
142
143 GEOM::GEOM_Gen_var GeometryGUI::myComponentGeom = GEOM::GEOM_Gen::_nil();
144
145 GEOM::GEOM_Gen_var GeometryGUI::GetGeomGen()
146 {
147   // Bug 12290: exception in Mesh GUI on GEOMBase::GetShape() if Geometry GUI hasn't been loaded
148   if (CORBA::is_nil(myComponentGeom))
149     InitGeomGen();
150   return GeometryGUI::myComponentGeom;
151 }
152
153 bool GeometryGUI::InitGeomGen()
154 {
155   GeometryGUI aGG;
156   if ( CORBA::is_nil( myComponentGeom ) ) return false;
157   return true;
158 }
159
160 //=======================================================================
161 // function : ClientSObjectToObject
162 // purpose  :
163 //=======================================================================
164 CORBA::Object_var GeometryGUI::ClientSObjectToObject (_PTR(SObject) theSObject)
165 {
166   _PTR(GenericAttribute) anAttr;
167   CORBA::Object_var anObj;
168   try {
169     std::string aValue = theSObject->GetIOR();
170     if (strcmp(aValue.c_str(), "") != 0) {
171       CORBA::ORB_ptr anORB = SalomeApp_Application::orb();
172       anObj = anORB->string_to_object(aValue.c_str());
173     }
174   } catch(...) {
175     INFOS("ClientSObjectToObject - Unknown exception has occurred!!!");
176   }
177   return anObj._retn();
178 }
179
180 //=======================================================================
181 // function : ClientStudyToStudy
182 // purpose  :
183 //=======================================================================
184 SALOMEDS::Study_var GeometryGUI::ClientStudyToStudy (_PTR(Study) theStudy)
185 {
186   SALOME_NamingService *aNamingService = SalomeApp_Application::namingService();
187   CORBA::Object_var aSMObject = aNamingService->Resolve("/myStudyManager");
188   SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(aSMObject);
189   int aStudyID = theStudy->StudyId();
190   SALOMEDS::Study_var aDSStudy = aStudyManager->GetStudyByID(aStudyID);
191   return aDSStudy._retn();
192 }
193
194 void GeometryGUI::Modified (bool theIsUpdateActions)
195 {
196   if ( SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() ) ) {
197     if ( SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) ) {
198       appStudy->Modified();
199       if ( theIsUpdateActions )
200         app->updateActions();
201     }
202   }
203 }
204
205 //=======================================================================
206 // function : GeometryGUI::GeometryGUI()
207 // purpose  : Constructor
208 //=======================================================================
209 GeometryGUI::GeometryGUI() :
210   SalomeApp_Module( "GEOM" ),
211   myTopLevelIOList()
212 {
213   if ( CORBA::is_nil( myComponentGeom ) )
214   {
215     Engines::EngineComponent_var comp =
216       SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "GEOM" );
217     myComponentGeom = GEOM::GEOM_Gen::_narrow( comp );
218   }
219
220   myActiveDialogBox = 0;
221
222   gp_Pnt origin = gp_Pnt(0., 0., 0.);
223   gp_Dir direction = gp_Dir(0., 0., 1.);
224   myWorkingPlane = gp_Ax3(origin, direction);
225
226   myDisplayer = 0;
227   myLocalSelectionMode = GEOM_ALLOBJECTS;
228
229   myCreationInfoWdg = 0;
230   myTextTreeWdg = 0;
231   myAnnotationMgr = 0;
232
233   connect( Material_ResourceMgr::resourceMgr(), SIGNAL( changed() ), this, SLOT( updateMaterials() ), Qt::UniqueConnection );
234
235   Q_INIT_RESOURCE( GEOMGUI );
236 }
237
238 //=======================================================================
239 // function : GeometryGUI::~GeometryGUI()
240 // purpose  : Destructor
241 //=======================================================================
242 GeometryGUI::~GeometryGUI()
243 {
244   while (!myOCCSelectors.isEmpty())
245     delete myOCCSelectors.takeFirst();
246
247   while (!myVTKSelectors.isEmpty())
248     delete myVTKSelectors.takeFirst();
249
250   qDeleteAll(myGUIMap);
251 }
252
253 //=======================================================================
254 // function : GeometryGUI::getLibrary()
255 // purpose  : get or load GUI library by name [ internal ]
256 //=======================================================================
257 typedef GEOMGUI* (*LibraryGUI)( GeometryGUI* );
258 GEOMGUI* GeometryGUI::getLibrary( const QString& libraryName )
259 {
260   if ( !myGUIMap.contains( libraryName ) ) {
261     // try to load library if it is not loaded yet
262 #if defined(WIN32)
263     QString dirs = getenv( "PATH" );
264 #elif defined(__APPLE__)
265     QString dirs = getenv( "DYLD_LIBRARY_PATH" );
266 #else
267     QString dirs = getenv( "LD_LIBRARY_PATH" );
268 #endif
269 #if defined(WIN32)
270     QString sep  = ";";
271 #else
272     QString sep  = ":";
273 #endif
274
275     if ( !dirs.isEmpty() ) {
276       QStringList dirList = dirs.split(sep, QString::SkipEmptyParts ); // skip empty entries
277       QListIterator<QString> it( dirList ); it.toBack();
278       while ( it.hasPrevious() ) {
279         QFileInfo fi( Qtx::addSlash( it.previous() ) + libraryName );
280         if ( fi.exists() ) {
281           OSD_SharedLibrary aSharedLibrary( fi.fileName().toLatin1().constData() );
282           bool res = aSharedLibrary.DlOpen( OSD_RTLD_LAZY );
283           if ( !res ) {
284             MESSAGE( "Can't open library : " << aSharedLibrary.DlError() );
285             continue; // continue search further
286           }
287           OSD_Function osdF = aSharedLibrary.DlSymb( "GetLibGUI" );
288           if ( osdF != NULL ) {
289             LibraryGUI func = (GEOMGUI* (*) (GeometryGUI*))osdF;
290             GEOMGUI* libGUI = (*func)( this );
291             if ( libGUI ) {
292               myGUIMap[ libraryName ] = libGUI;
293               break; // found and loaded!
294             }
295           }
296         }
297       }
298     }
299   }
300   return myGUIMap.contains( libraryName ) ? myGUIMap[ libraryName ] : 0;
301 }
302
303 //=======================================================================
304 // function : GeometryGUI::getPluginLibrary()
305 // purpose  : get or load GUI Plugin library by name [ internal ]
306 //=======================================================================
307 typedef GEOMPluginGUI* (*PluginLibraryGUI)( GeometryGUI* );
308 GEOMPluginGUI* GeometryGUI::getPluginLibrary( const QString& libraryName )
309 {
310   if ( !myGUIMap.contains( libraryName ) ) {
311     // try to load library if it is not loaded yet
312
313 #if defined(WIN32)
314     QString dirs = getenv( "PATH" );
315 #elif defined(__APPLE__)
316     QString dirs = getenv( "DYLD_LIBRARY_PATH" );
317 #else
318     QString dirs = getenv( "LD_LIBRARY_PATH" );
319 #endif
320 #if defined(WIN32)
321     QString sep  = ";";
322 #else
323     QString sep  = ":";
324 #endif
325
326     if ( !dirs.isEmpty() ) {
327       QStringList dirList = dirs.split(sep, QString::SkipEmptyParts ); // skip empty entries
328       QListIterator<QString> it( dirList ); it.toBack();
329       while ( it.hasPrevious() ) {
330         QFileInfo fi( Qtx::addSlash( it.previous() ) + libraryName );
331         if ( fi.exists() ) {
332           OSD_SharedLibrary aSharedLibrary( fi.fileName().toLatin1().constData() );
333           bool res = aSharedLibrary.DlOpen( OSD_RTLD_LAZY );
334           if ( !res ) {
335             MESSAGE( "Can't open library : " << aSharedLibrary.DlError() );
336             continue; // continue search further
337           }
338           OSD_Function osdF = aSharedLibrary.DlSymb( "GetLibGUI" );
339           if ( osdF != NULL ) {
340             PluginLibraryGUI func = (GEOMPluginGUI* (*) (GeometryGUI*))osdF;
341             GEOMPluginGUI* libGUI = (*func)( this );
342             if ( libGUI ) {
343               myGUIMap[ libraryName ] = libGUI;
344               break; // found and loaded!
345             }
346           }
347         }
348       }
349     }
350   }
351   return myGUIMap.contains( libraryName ) ? (GEOMPluginGUI*)myGUIMap[ libraryName ] : 0;
352 }
353
354 //=======================================================================
355 // function : GeometryGUI::ActiveWorkingPlane()
356 // purpose  : Activate Working Plane View
357 //=======================================================================
358 void GeometryGUI::ActiveWorkingPlane()
359 {
360   gp_Dir DZ = myWorkingPlane.Direction();
361   gp_Dir DY = myWorkingPlane.YDirection();
362
363   SUIT_ViewWindow* window = application()->desktop()->activeWindow();
364   bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
365   bool ViewVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
366
367   if ( ViewOCC ) {
368     OCCViewer_ViewWindow* vw = dynamic_cast<OCCViewer_ViewWindow*>( window );
369     if ( vw ) {
370       Handle(V3d_View) view3d =  vw->getViewPort()->getView();
371
372       view3d->SetProj(DZ.X(), DZ.Y(), DZ.Z());
373       view3d->SetUp(DY.X(), DY.Y(), DY.Z());
374       vw->onViewFitAll();
375     }
376   }
377   else if ( ViewVTK ) {
378     SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( window );
379     if ( vw ) {
380       vtkCamera* camera = vw->getRenderer()->GetActiveCamera();
381
382       camera->SetPosition(DZ.X(), DZ.Y(), DZ.Z());
383       camera->SetViewUp(DY.X(), DY.Y(), DY.Z());
384       camera->SetFocalPoint(0,0,0);
385
386       vw->onFitAll();
387     }
388   }
389 }
390
391 //=======================================================================
392 // function : GeometryGUI::SetActiveDialogBox()
393 // purpose  : Set active dialog box
394 //=======================================================================
395 GEOMGUI_AnnotationMgr* GeometryGUI::GetAnnotationMgr()
396 {
397   if ( !myAnnotationMgr )
398     myAnnotationMgr = new GEOMGUI_AnnotationMgr( getApp() );
399   return myAnnotationMgr;
400 }
401
402 //=======================================================================
403 // function : GeometryGUI::SetActiveDialogBox()
404 // purpose  : Set active dialog box
405 //=======================================================================
406 GEOMGUI_TextTreeWdg* GeometryGUI::GetTextTreeWdg() const
407 {
408   return myTextTreeWdg;
409 }
410
411 //=======================================================================
412 // function : GeometryGUI::SetActiveDialogBox()
413 // purpose  : Set active dialog box
414 //=======================================================================
415 void GeometryGUI::SetActiveDialogBox( QDialog* aDlg )
416 {
417   myActiveDialogBox = (QDialog*)aDlg;
418 }
419
420 //=======================================================================
421 // function : GeometryGUI::EmitSignalDeactivateDialog()
422 // purpose  : Emit a signal to deactivate the active dialog Box
423 //=======================================================================
424 void GeometryGUI::EmitSignalDeactivateDialog()
425 {
426   emit SignalDeactivateActiveDialog();
427 }
428
429 //=======================================================================
430 // function : GeometryGUI::EmitSignalCloseAllDialogs()
431 // purpose  : Emit a signal to close all non modal dialogs box
432 //=======================================================================
433 void GeometryGUI::EmitSignalCloseAllDialogs()
434 {
435   emit SignalCloseAllDialogs();
436 }
437
438 //=======================================================================
439 // function : GeometryGUI::EmitSignalDefaultStepValueChanged()
440 // purpose  : Emit a signal to inform that default real spin box step has
441 //            been changed
442 //=======================================================================
443 void GeometryGUI::EmitSignalDefaultStepValueChanged(double newVal)
444 {
445   emit SignalDefaultStepValueChanged(newVal);
446 }
447
448 //=======================================================================
449 // function : GeometryGUI::OnGUIEvent()
450 // purpose  : common slot for all menu/toolbar actions
451 //=======================================================================
452 void GeometryGUI::OnGUIEvent()
453 {
454   const QObject* obj = sender();
455   if ( !obj || !obj->inherits( "QAction" ) )
456     return;
457   int id = actionId((QAction*)obj);
458   if ( id != -1 )
459     OnGUIEvent( id );
460 }
461
462 //=======================================================================
463 // function : GeometryGUI::OnGUIEvent()
464 // purpose  : manage all events on GUI [static]
465 //=======================================================================
466 void GeometryGUI::OnGUIEvent( int id, const QVariant& theParam )
467 {
468   SUIT_Application* anApp = application();
469   if (!anApp) return;
470   SUIT_Desktop* desk = anApp->desktop();
471
472   // check type of the active viewframe
473   SUIT_ViewWindow* window = desk->activeWindow();
474   bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
475   bool ViewVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
476 #ifndef DISABLE_GRAPHICSVIEW
477   bool ViewDep = ( window && window->getViewManager()->getType() == GraphicsView_Viewer::Type() );
478 #else
479   bool ViewDep = 0;
480 #endif
481   // if current viewframe is not of OCC and not of VTK type - return immediately
482   // fix for IPAL8958 - allow some commands to execute even when NO viewer is active (rename for example)
483   QList<int> NotViewerDependentCommands;
484   NotViewerDependentCommands << GEOMOp::OpDelete
485                              << GEOMOp::OpShow
486                              << GEOMOp::OpShowOnly
487                              << GEOMOp::OpShowOnlyChildren
488                              << GEOMOp::OpDiscloseChildren
489                              << GEOMOp::OpConcealChildren
490                              << GEOMOp::OpUnpublishObject
491                              << GEOMOp::OpPublishObject
492                              << GEOMOp::OpPointMarker
493                              << GEOMOp::OpCreateFolder
494                              << GEOMOp::OpSortChildren;
495   if ( !ViewOCC && !ViewVTK && !ViewDep && !NotViewerDependentCommands.contains( id ) ) {
496     // activate OCC viewer
497     getApp()->getViewManager(OCCViewer_Viewer::Type(), /*create=*/true);
498   }
499
500   // fix for IPAL9103, point 2
501   if ( CORBA::is_nil( GetGeomGen() ) ) {
502     SUIT_MessageBox::critical( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_GET_ENGINE" ), tr( "GEOM_BUT_OK" ) );
503     return;
504   }
505
506   QString libName;
507   // find corresponding GUI library
508   switch ( id ) {
509   case GEOMOp::OpOriginAndVectors:   // MENU BASIC - ORIGIN AND BASE VECTORS
510     createOriginAndBaseVectors(); // internal operation
511     return;
512   case GEOMOp::OpSelectVertex:       // POPUP MENU - SELECT ONLY - VERTEX
513   case GEOMOp::OpSelectEdge:         // POPUP MENU - SELECT ONLY - EDGE
514   case GEOMOp::OpSelectWire:         // POPUP MENU - SELECT ONLY - WIRE
515   case GEOMOp::OpSelectFace:         // POPUP MENU - SELECT ONLY - FACE
516   case GEOMOp::OpSelectShell:        // POPUP MENU - SELECT ONLY - SHELL
517   case GEOMOp::OpSelectSolid:        // POPUP MENU - SELECT ONLY - SOLID
518   case GEOMOp::OpSelectCompound:     // POPUP MENU - SELECT ONLY - COMPOUND
519   case GEOMOp::OpSelectAll:          // POPUP MENU - SELECT ONLY - SELECT ALL
520   case GEOMOp::OpDelete:             // MENU EDIT - DELETE
521 #ifndef DISABLE_PYCONSOLE
522   case GEOMOp::OpCheckGeom:          // MENU TOOLS - CHECK GEOMETRY
523 #endif
524   case GEOMOp::OpMaterialsLibrary:   // MENU TOOLS - MATERIALS LIBRARY
525   case GEOMOp::OpDeflection:         // POPUP MENU - DEFLECTION COEFFICIENT
526   case GEOMOp::OpColor:              // POPUP MENU - COLOR
527   case GEOMOp::OpSetTexture:         // POPUP MENU - SETTEXTURE
528   case GEOMOp::OpTransparency:       // POPUP MENU - TRANSPARENCY
529   case GEOMOp::OpIncrTransparency:   // SHORTCUT   - INCREASE TRANSPARENCY
530   case GEOMOp::OpDecrTransparency:   // SHORTCUT   - DECREASE TRANSPARENCY
531   case GEOMOp::OpIsos:               // POPUP MENU - ISOS
532   case GEOMOp::OpIncrNbIsos:         // SHORTCUT   - INCREASE NB ISOS
533   case GEOMOp::OpDecrNbIsos:         // SHORTCUT   - DECREASE NB ISOS
534   case GEOMOp::OpAutoColor:          // POPUP MENU - AUTO COLOR
535   case GEOMOp::OpNoAutoColor:        // POPUP MENU - DISABLE AUTO COLOR
536   case GEOMOp::OpDiscloseChildren:   // POPUP MENU - DISCLOSE CHILD ITEMS
537   case GEOMOp::OpConcealChildren:    // POPUP MENU - CONCEAL CHILD ITEMS
538   case GEOMOp::OpUnpublishObject:    // POPUP MENU - UNPUBLISH
539   case GEOMOp::OpPublishObject:      // ROOT GEOM OBJECT - POPUP MENU - PUBLISH
540   case GEOMOp::OpPointMarker:        // POPUP MENU - POINT MARKER
541   case GEOMOp::OpMaterialProperties: // POPUP MENU - MATERIAL PROPERTIES
542   case GEOMOp::OpPredefMaterial:     // POPUP MENU - <SOME MATERIAL>
543   case GEOMOp::OpPredefMaterCustom:  // POPUP MENU - MATERIAL PROPERTIES - CUSTOM...
544   case GEOMOp::OpEdgeWidth:          // POPUP MENU - LINE WIDTH - EDGE WIDTH
545   case GEOMOp::OpIsosWidth:          // POPUP MENU - LINE WIDTH - ISOS WIDTH
546   case GEOMOp::OpBringToFront:       // POPUP MENU - BRING TO FRONT
547   case GEOMOp::OpClsBringToFront:    //
548   case GEOMOp::OpCreateFolder:       // POPUP MENU - CREATE FOLDER
549   case GEOMOp::OpSortChildren:       // POPUP MENU - SORT CHILD ITEMS
550 #ifndef DISABLE_GRAPHICSVIEW
551   case GEOMOp::OpShowDependencyTree: // POPUP MENU - SHOW DEPENDENCY TREE
552 #endif
553   case GEOMOp::OpReduceStudy:        // POPUP MENU - REDUCE STUDY
554     libName = "GEOMToolsGUI";
555     break;
556   case GEOMOp::OpDMWireframe:        // MENU VIEW - WIREFRAME
557   case GEOMOp::OpDMShading:          // MENU VIEW - SHADING
558   case GEOMOp::OpDMShadingWithEdges: // MENU VIEW - SHADING
559   case GEOMOp::OpDMTexture:          // MENU VIEW - TEXTURE
560   case GEOMOp::OpShowAll:            // MENU VIEW - SHOW ALL
561   case GEOMOp::OpShowOnly:           // MENU VIEW - DISPLAY ONLY
562   case GEOMOp::OpShowOnlyChildren:   // MENU VIEW - SHOW ONLY CHILDREN
563   case GEOMOp::OpHideAll:            // MENU VIEW - ERASE ALL
564   case GEOMOp::OpHide:               // MENU VIEW - ERASE
565   case GEOMOp::OpShow:               // MENU VIEW - DISPLAY
566   case GEOMOp::OpSwitchVectors:      // MENU VIEW - VECTOR MODE
567   case GEOMOp::OpSwitchVertices:     // MENU VIEW - VERTICES MODE
568   case GEOMOp::OpSwitchName:         // MENU VIEW - VERTICES MODE
569   case GEOMOp::OpWireframe:          // POPUP MENU - WIREFRAME
570   case GEOMOp::OpShading:            // POPUP MENU - SHADING
571   case GEOMOp::OpShadingWithEdges:   // POPUP MENU - SHADING WITH EDGES
572   case GEOMOp::OpTexture:            // POPUP MENU - TEXTURE
573   case GEOMOp::OpVectors:            // POPUP MENU - VECTORS
574   case GEOMOp::OpVertices:           // POPUP MENU - VERTICES
575   case GEOMOp::OpShowName:           // POPUP MENU - SHOW NAME
576     libName = "DisplayGUI";
577     break;
578   case GEOMOp::OpPoint:              // MENU BASIC - POINT
579   case GEOMOp::OpLine:               // MENU BASIC - LINE
580   case GEOMOp::OpCircle:             // MENU BASIC - CIRCLE
581   case GEOMOp::OpEllipse:            // MENU BASIC - ELLIPSE
582   case GEOMOp::OpArc:                // MENU BASIC - ARC
583   case GEOMOp::OpVector:             // MENU BASIC - VECTOR
584   case GEOMOp::OpPlane:              // MENU BASIC - PLANE
585   case GEOMOp::OpCurve:              // MENU BASIC - CURVE
586   case GEOMOp::OpLCS:                // MENU BASIC - LOCAL COORDINATE SYSTEM
587     libName = "BasicGUI";
588     break;
589   case GEOMOp::OpBox:                // MENU PRIMITIVE - BOX
590   case GEOMOp::OpCylinder:           // MENU PRIMITIVE - CYLINDER
591   case GEOMOp::OpSphere:             // MENU PRIMITIVE - SPHERE
592   case GEOMOp::OpTorus:              // MENU PRIMITIVE - TORUS
593   case GEOMOp::OpCone:               // MENU PRIMITIVE - CONE
594   case GEOMOp::OpRectangle:          // MENU PRIMITIVE - FACE
595   case GEOMOp::OpDisk:               // MENU PRIMITIVE - DISK
596     libName = "PrimitiveGUI";
597     break;
598   case GEOMOp::OpPrism:              // MENU GENERATION - PRISM
599   case GEOMOp::OpRevolution:         // MENU GENERATION - REVOLUTION
600   case GEOMOp::OpFilling:            // MENU GENERATION - FILLING
601   case GEOMOp::OpPipe:               // MENU GENERATION - PIPE
602   case GEOMOp::OpPipePath:           // MENU GENERATION - RESTORE PATH
603   case GEOMOp::OpThickness:          // MENU GENERATION - THICKNESS
604     libName = "GenerationGUI";
605     break;
606   case GEOMOp::Op2dSketcher:         // MENU ENTITY - SKETCHER
607   case GEOMOp::Op3dSketcher:         // MENU ENTITY - 3D SKETCHER
608   case GEOMOp::OpIsoline:            // MENU BASIC  - ISOLINE
609   case GEOMOp::OpExplode:            // MENU ENTITY - EXPLODE
610   case GEOMOp::OpSurfaceFromFace:    // MENU ENTITY - SURFACE FROM FACE
611 #ifdef WITH_OPENCV
612   case GEOMOp::OpFeatureDetect:      // MENU ENTITY - FEATURE DETECTION
613 #endif
614   case GEOMOp::OpPictureImport:      // MENU ENTITY - IMPORT PICTURE IN VIEWER
615   case GEOMOp::OpCreateField:        // MENU FIELD - CREATE FIELD
616   case GEOMOp::OpEditField:          // MENU FIELD - EDIT FIELD
617   case GEOMOp::OpEditFieldPopup:     // POPUP MENU - EDIT FIELD
618   case GEOMOp::Op2dPolylineEditor:   // MENU BASIC - POLYLINE EDITOR
619     libName = "EntityGUI";
620     break;
621   case GEOMOp::OpEdge:               // MENU BUILD - EDGE
622   case GEOMOp::OpWire:               // MENU BUILD - WIRE
623   case GEOMOp::OpFace:               // MENU BUILD - FACE
624   case GEOMOp::OpShell:              // MENU BUILD - SHELL
625   case GEOMOp::OpSolid:              // MENU BUILD - SOLID
626   case GEOMOp::OpCompound:           // MENU BUILD - COMPOUND
627     libName = "BuildGUI";
628     break;
629   case GEOMOp::OpFuse:               // MENU BOOLEAN - FUSE
630   case GEOMOp::OpCommon:             // MENU BOOLEAN - COMMON
631   case GEOMOp::OpCut:                // MENU BOOLEAN - CUT
632   case GEOMOp::OpSection:            // MENU BOOLEAN - SECTION
633     libName = "BooleanGUI";
634     break;
635   case GEOMOp::OpTranslate:          // MENU TRANSFORMATION - TRANSLATION
636   case GEOMOp::OpRotate:             // MENU TRANSFORMATION - ROTATION
637   case GEOMOp::OpChangeLoc:          // MENU TRANSFORMATION - LOCATION
638   case GEOMOp::OpMirror:             // MENU TRANSFORMATION - MIRROR
639   case GEOMOp::OpScale:              // MENU TRANSFORMATION - SCALE
640   case GEOMOp::OpOffset:             // MENU TRANSFORMATION - OFFSET
641   case GEOMOp::OpProjection:         // MENU TRANSFORMATION - PROJECTION
642   case GEOMOp::OpProjOnCyl:          // MENU TRANSFORMATION - PROJECTION ON CYLINDER
643   case GEOMOp::OpMultiTranslate:     // MENU TRANSFORMATION - MULTI-TRANSLATION
644   case GEOMOp::OpMultiRotate:        // MENU TRANSFORMATION - MULTI-ROTATION
645   case GEOMOp::OpReimport:           // CONTEXT(POPUP) MENU - RELOAD_IMPORTED
646   case GEOMOp::OpExtension:          // MENU TRANSFORMATION - EXTENSION
647     libName = "TransformationGUI";
648     break;
649   case GEOMOp::OpPartition:          // MENU OPERATION - PARTITION
650   case GEOMOp::OpArchimede:          // MENU OPERATION - ARCHIMEDE
651   case GEOMOp::OpFillet3d:           // MENU OPERATION - FILLET
652   case GEOMOp::OpChamfer:            // MENU OPERATION - CHAMFER
653   case GEOMOp::OpShapesOnShape:      // MENU OPERATION - GET SHAPES ON SHAPE
654   case GEOMOp::OpFillet2d:           // MENU OPERATION - FILLET 2D
655   case GEOMOp::OpFillet1d:           // MENU OPERATION - FILLET 1D
656   case GEOMOp::OpSharedShapes:       // MENU OPERATION - GET SHARED SHAPES
657   case GEOMOp::OpExtrudedBoss:       // MENU OPERATION - EXTRUDED BOSS
658   case GEOMOp::OpExtrudedCut:        // MENU OPERATION - EXTRUDED CUT
659   case GEOMOp::OpTransferData:       // MENU OPERATION - TRANSFER DATA
660   case GEOMOp::OpExtraction:         // MENU OPERATION - EXTRACT AND REBUILD
661     libName = "OperationGUI";
662     break;
663   case GEOMOp::OpSewing:             // MENU REPAIR - SEWING
664   case GEOMOp::OpSuppressFaces:      // MENU REPAIR - SUPPRESS FACES
665   case GEOMOp::OpSuppressHoles:      // MENU REPAIR - SUPPRESS HOLE
666   case GEOMOp::OpShapeProcess:       // MENU REPAIR - SHAPE PROCESSING
667   case GEOMOp::OpCloseContour:       // MENU REPAIR - CLOSE CONTOUR
668   case GEOMOp::OpRemoveIntWires:     // MENU REPAIR - REMOVE INTERNAL WIRES
669   case GEOMOp::OpAddPointOnEdge:     // MENU REPAIR - ADD POINT ON EDGE
670   case GEOMOp::OpFreeBoundaries:     // MENU MEASURE - FREE BOUNDARIES
671   case GEOMOp::OpFreeFaces:          // MENU MEASURE - FREE FACES
672   case GEOMOp::OpOrientation:        // MENU REPAIR - CHANGE ORIENTATION
673   case GEOMOp::OpGlueFaces:          // MENU REPAIR - GLUE FACES
674   case GEOMOp::OpGlueEdges:          // MENU REPAIR - GLUE EDGES
675   case GEOMOp::OpLimitTolerance:     // MENU REPAIR - LIMIT TOLERANCE
676   case GEOMOp::OpRemoveWebs:         // MENU REPAIR - REMOVE INTERNAL FACES
677   case GEOMOp::OpRemoveExtraEdges:   // MENU REPAIR - REMOVE EXTRA EDGES
678   case GEOMOp::OpFuseEdges:          // MENU REPAIR - FUSE COLLINEAR EDGES
679   case GEOMOp::OpUnionFaces:         // MENU REPAIR - UNION FACES
680   case GEOMOp::OpInspectObj:         // MENU REPAIR - INSPECT OBJECT
681     libName = "RepairGUI";
682     break;
683   case GEOMOp::OpProperties:         // MENU MEASURE - PROPERTIES
684   case GEOMOp::OpCenterMass:         // MENU MEASURE - CDG
685   case GEOMOp::OpInertia:            // MENU MEASURE - INERTIA
686   case GEOMOp::OpNormale:            // MENU MEASURE - NORMALE
687   case GEOMOp::OpBoundingBox:        // MENU MEASURE - BOUNDING BOX
688   case GEOMOp::OpMinDistance:        // MENU MEASURE - MIN DISTANCE
689   case GEOMOp::OpAngle:              // MENU MEASURE - ANGLE
690   case GEOMOp::OpTolerance:          // MENU MEASURE - TOLERANCE
691   case GEOMOp::OpWhatIs:             // MENU MEASURE - WHATIS
692   case GEOMOp::OpCheckShape:         // MENU MEASURE - CHECK
693   case GEOMOp::OpCheckCompound:      // MENU MEASURE - CHECK COMPOUND OF BLOCKS
694   case GEOMOp::OpGetNonBlocks:       // MENU MEASURE - Get NON BLOCKS
695   case GEOMOp::OpPointCoordinates:   // MENU MEASURE - POINT COORDINATES
696   case GEOMOp::OpCheckSelfInters:    // MENU MEASURE - CHECK SELF INTERSECTIONS
697   case GEOMOp::OpFastCheckInters:    // MENU MEASURE - FAST CHECK INTERSECTIONS
698   case GEOMOp::OpManageDimensions:   // MENU MEASURE - MANAGE DIMENSIONS
699   case GEOMOp::OpAnnotation:         // MENU MEASURE - ANNOTATION
700   case GEOMOp::OpEditAnnotation:     // POPUP MENU - EDIT ANNOTATION
701   case GEOMOp::OpDeleteAnnotation:   // POPUP MENU - DELETE ANNOTATION
702 #ifndef DISABLE_PLOT2DVIEWER
703   case GEOMOp::OpShapeStatistics:    // MENU MEASURE - SHAPE STATISTICS
704 #endif
705   case GEOMOp::OpShowAllDimensions:  // POPUP MENU - SHOW ALL DIMENSIONS
706   case GEOMOp::OpHideAllDimensions:  // POPUP MENU - HIDE ALL DIMENSIONS
707   case GEOMOp::OpShowAllAnnotations: // POPUP MENU - SHOW ALL ANNOTATIONS
708   case GEOMOp::OpHideAllAnnotations: // POPUP MENU - HIDE ALL ANNOTATIONS
709     libName = "MeasureGUI";
710     break;
711   case GEOMOp::OpGroupCreate:        // MENU GROUP - CREATE
712   case GEOMOp::OpGroupCreatePopup:   // POPUP MENU - CREATE GROUP
713   case GEOMOp::OpGroupEdit:          // MENU GROUP - EDIT
714   case GEOMOp::OpGroupUnion:         // MENU GROUP - UNION
715   case GEOMOp::OpGroupIntersect:     // MENU GROUP - INTERSECT
716   case GEOMOp::OpGroupCut:           // MENU GROUP - CUT
717     libName = "GroupGUI";
718     break;
719   case GEOMOp::OpHexaSolid:          // MENU BLOCKS - HEXAHEDRAL SOLID
720   case GEOMOp::OpMultiTransform:     // MENU BLOCKS - MULTI-TRANSFORMATION
721   case GEOMOp::OpQuadFace:           // MENU BLOCKS - QUADRANGLE FACE
722   case GEOMOp::OpPropagate:          // MENU BLOCKS - PROPAGATE
723   case GEOMOp::OpExplodeBlock:       // MENU BLOCKS - EXPLODE ON BLOCKS
724     libName = "BlocksGUI";
725     break;
726   //case GEOMOp::OpAdvancedNoOp:       // NO OPERATION (advanced operations base)
727   //case GEOMOp::OpPipeTShape:         // MENU NEW ENTITY - ADVANCED - PIPE TSHAPE
728   //case GEOMOp::OpPipeTShapeGroups:     // MENU NEW ENTITY - ADVANCED - PIPE TSHAPE GROUPS
729   //case GEOMOp::OpDividedDisk:           // MENU NEW ENTITY - ADVANCED - DIVIDEDDISK
730   //case GEOMOp::OpDividedCylinder:           // MENU NEW ENTITY - ADVANCED - DIVIDEDCYLINDER
731   //case GEOMOp::OpSmoothingSurface:           // MENU NEW ENTITY - ADVANCED - SMOOTHINGSURFACE
732     //@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@//
733     //libName = "AdvancedGUI";
734     //break;
735   default:
736     if (myPluginActions.contains(id)) {
737       libName = myPluginActions[id].first;
738
739       GEOMPluginGUI* library = 0;
740       if ( !libName.isEmpty() ) {
741 #if defined(WIN32)
742         libName = libName + ".dll";
743 #elif defined(__APPLE__)
744         libName = QString( "lib" ) + libName + ".dylib";
745 #else
746         libName = QString( "lib" ) + libName + ".so";
747 #endif
748         library = getPluginLibrary( libName );
749       }
750
751       // call method of corresponding GUI library
752       if ( library ) {
753         //QString action ("%1");
754         //action = action.arg(id);
755
756         //if( !theParam.isValid() )
757           library->OnGUIEvent( myPluginActions[id].second, desk );
758         //else
759         //  library->OnGUIEvent( id, desk, theParam);
760       }
761       else
762         SUIT_MessageBox::critical( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_LIB_NOT_FOUND" ), tr( "GEOM_BUT_OK" ) );
763
764       updateCreationInfo();
765       return;
766     }
767     break;
768   }
769
770   GEOMGUI* library = 0;
771   if ( !libName.isEmpty() ) {
772 #if defined(WIN32)
773     libName = libName + ".dll";
774 #elif defined(__APPLE__)
775     libName = QString( "lib" ) + libName + ".dylib";
776 #else
777     libName = QString( "lib" ) + libName + ".so";
778 #endif
779     library = getLibrary( libName );
780   }
781
782   // call method of corresponding GUI library
783   if ( library ) {
784     if( !theParam.isValid() )
785       library->OnGUIEvent( id, desk );
786     else
787       library->OnGUIEvent( id, desk, theParam);
788   }
789   else
790     SUIT_MessageBox::critical( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_LIB_NOT_FOUND" ), tr( "GEOM_BUT_OK" ) );
791
792   updateCreationInfo();
793 }
794
795 //=================================================================================
796 // function : GeometryGUI::activateOperation()
797 // purpose  :
798 //=================================================================================
799 bool GeometryGUI::activateOperation( int actionId )
800 {
801   OnGUIEvent(actionId);
802   return true;
803 }
804
805 //=================================================================================
806 // function : GeometryGUI::activateOperation()
807 // purpose  :
808 //=================================================================================
809 bool GeometryGUI::activateOperation( const QString& actionId )
810 {
811   bool isOk = false;
812
813   int id = actionId.toInt(&isOk);
814   if (isOk)
815     OnGUIEvent(id);
816
817   return isOk;
818 }
819
820 //=================================================================================
821 // function : GeometryGUI::activateOperation()
822 // purpose  :
823 //=================================================================================
824 bool GeometryGUI::activateOperation( const QString& actionId, const QString& plugin )
825 {
826   bool isOk = false;
827
828   QString pluginLib = plugin;
829   // TODO: if <plugin> is a plugin name, find plugin library name
830   if (myPluginLibs.contains(plugin))
831     pluginLib = myPluginLibs[plugin];
832
833   QMap<int, PluginAction>::iterator actionsIter = myPluginActions.begin();
834   for (; actionsIter != myPluginActions.end(); ++actionsIter) {
835     const PluginAction& anAction = actionsIter.value();
836     if (anAction.first == pluginLib && anAction.second == actionId) {
837       // activate operation
838       OnGUIEvent(actionsIter.key());
839       isOk = true;
840     }
841   }
842
843   return isOk;
844 }
845
846 //=================================================================================
847 // function : GeometryGUI::OnKeyPress()
848 // purpose  : Called when any key is pressed by user [static]
849 //=================================================================================
850 void GeometryGUI::OnKeyPress( SUIT_ViewWindow* w, QKeyEvent* e )
851 {
852   if ( !application() )
853     return;
854   foreach ( GEOMGUI* lib, myGUIMap )
855     lib->OnKeyPress( e, application()->desktop(), w );
856 }
857
858 //=================================================================================
859 // function : GeometryGUI::OnMouseMove()
860 // purpose  : Manages mouse move events [static]
861 //=================================================================================
862 void GeometryGUI::OnMouseMove( SUIT_ViewWindow* w, QMouseEvent* e )
863 {
864   if ( !application() )
865     return;
866   foreach ( GEOMGUI* lib, myGUIMap )
867     lib->OnMouseMove( e, application()->desktop(), w );
868 }
869
870 //=================================================================================
871 // function : GeometryGUI::OnMouseRelease()
872 // purpose  : Manages mouse release events [static]
873 //=================================================================================
874 void GeometryGUI::OnMouseRelease( SUIT_ViewWindow* w, QMouseEvent* e )
875 {
876   if ( !application() )
877     return;
878   foreach ( GEOMGUI* lib, myGUIMap )
879     lib->OnMouseRelease( e, application()->desktop(), w );
880 }
881
882 //=================================================================================
883 // function : GeometryGUI::OnMousePress()
884 // purpose  : Manage mouse press events [static]
885 //=================================================================================
886 void GeometryGUI::OnMousePress( SUIT_ViewWindow* w, QMouseEvent* e )
887 {
888   if ( !application() )
889     return;
890   foreach ( GEOMGUI* lib, myGUIMap )
891     lib->OnMousePress( e, application()->desktop(), w );
892 }
893
894 //=======================================================================
895 // function : createGeomAction
896 // purpose  :
897 //=======================================================================
898 void GeometryGUI::createGeomAction( const int id, const QString& label, const QString& icolabel,
899                                     const int accel, const bool toggle, const QString& shortcutAction )
900 {
901   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
902   QPixmap icon = icolabel.isEmpty() ? resMgr->loadPixmap( "GEOM", tr( (QString( "ICO_" )+label).toLatin1().constData() ), false )
903                                     : resMgr->loadPixmap( "GEOM", tr( icolabel.toLatin1().constData() ) );
904   createAction( id,
905                 tr( QString( "TOP_%1" ).arg( label ).toLatin1().constData() ),
906                 icon,
907                 tr( QString( "MEN_%1" ).arg( label ).toLatin1().constData() ),
908                 tr( QString( "STB_%1" ).arg( label ).toLatin1().constData() ),
909                 accel,
910                 application()->desktop(),
911                 toggle,
912                 this, SLOT( OnGUIEvent() ),
913                 shortcutAction );
914 }
915
916 //=======================================================================
917 // function : createOriginAndBaseVectors
918 // purpose  :
919 //=======================================================================
920 void GeometryGUI::createOriginAndBaseVectors()
921 {
922   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
923   bool aLocked = (_PTR(AttributeStudyProperties)(appStudy->studyDS()->GetProperties()))->IsLocked();
924   if ( aLocked ) {
925     SUIT_MessageBox::warning ( application()->desktop(), QObject::tr("WRN_WARNING"), QObject::tr("WRN_STUDY_LOCKED") );
926     return;
927   }
928   if ( appStudy ) {
929     _PTR(Study) studyDS = appStudy->studyDS();
930     if ( studyDS && !CORBA::is_nil( GetGeomGen() ) ) {
931       GEOM::GEOM_IBasicOperations_var aBasicOperations = GetGeomGen()->GetIBasicOperations( studyDS->StudyId() );
932       if ( !aBasicOperations->_is_nil() ) {
933         SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
934         double aLength = aResourceMgr->doubleValue( "Geometry", "base_vectors_length", 1.0 );
935         GEOM::GEOM_Object_var anOrigin = aBasicOperations->MakePointXYZ( 0.0, 0.0, 0.0 );
936         GEOM::GEOM_Object_var anOX = aBasicOperations->MakeVectorDXDYDZ( aLength, 0.0, 0.0 );
937         GEOM::GEOM_Object_var anOY = aBasicOperations->MakeVectorDXDYDZ( 0.0, aLength, 0.0 );
938         GEOM::GEOM_Object_var anOZ = aBasicOperations->MakeVectorDXDYDZ( 0.0, 0.0, aLength );
939
940         SALOMEDS::Study_var aDSStudy = ClientStudyToStudy( studyDS );
941         GetGeomGen()->PublishInStudy( aDSStudy, SALOMEDS::SObject::_nil(), anOrigin, "O" );
942         GetGeomGen()->PublishInStudy( aDSStudy, SALOMEDS::SObject::_nil(), anOX, "OX" );
943         GetGeomGen()->PublishInStudy( aDSStudy, SALOMEDS::SObject::_nil(), anOY, "OY" );
944         GetGeomGen()->PublishInStudy( aDSStudy, SALOMEDS::SObject::_nil(), anOZ, "OZ" );
945         anOrigin->UnRegister();
946         anOX->UnRegister();
947         anOY->UnRegister();
948         anOZ->UnRegister();
949         aBasicOperations->UnRegister();
950
951         getApp()->updateObjectBrowser( true );
952       }
953     }
954   }
955 }
956
957 //=======================================================================
958 // function : GeometryGUI::initialize()
959 // purpose  : Called when GEOM module is created
960 //=======================================================================
961 void GeometryGUI::initialize( CAM_Application* app )
962 {
963   SalomeApp_Module::initialize( app );
964
965   // ----- create actions --------------
966
967   createGeomAction( GEOMOp::OpDelete,     "DELETE", "", Qt::Key_Delete );
968
969   createGeomAction( GEOMOp::OpPoint,      "POINT" );
970   createGeomAction( GEOMOp::OpLine,       "LINE" );
971   createGeomAction( GEOMOp::OpCircle,     "CIRCLE" );
972   createGeomAction( GEOMOp::OpEllipse,    "ELLIPSE" );
973   createGeomAction( GEOMOp::OpArc,        "ARC" );
974   createGeomAction( GEOMOp::OpCurve,      "CURVE" );
975   createGeomAction( GEOMOp::OpIsoline,    "ISOLINE" );
976   createGeomAction( GEOMOp::OpVector,     "VECTOR" );
977   createGeomAction( GEOMOp::OpPlane,      "PLANE" );
978   createGeomAction( GEOMOp::OpLCS,        "LOCAL_CS" );
979   createGeomAction( GEOMOp::OpOriginAndVectors, "ORIGIN_AND_VECTORS" );
980   createGeomAction( GEOMOp::OpSurfaceFromFace,  "SURFACE_FROM_FACE" );
981
982   createGeomAction( GEOMOp::OpBox,        "BOX" );
983   createGeomAction( GEOMOp::OpCylinder,   "CYLINDER" );
984   createGeomAction( GEOMOp::OpSphere,     "SPHERE" );
985   createGeomAction( GEOMOp::OpTorus,      "TORUS" );
986   createGeomAction( GEOMOp::OpCone,       "CONE" );
987   createGeomAction( GEOMOp::OpRectangle,  "RECTANGLE" );
988   createGeomAction( GEOMOp::OpDisk,       "DISK" );
989
990   createGeomAction( GEOMOp::OpPrism,       "EXTRUSION" );
991   createGeomAction( GEOMOp::OpRevolution,  "REVOLUTION" );
992   createGeomAction( GEOMOp::OpFilling,     "FILLING" );
993   createGeomAction( GEOMOp::OpPipe,        "PIPE" );
994   createGeomAction( GEOMOp::OpPipePath,    "PIPE_PATH" );
995   createGeomAction( GEOMOp::OpThickness,   "THICKNESS" );
996
997   createGeomAction( GEOMOp::OpGroupCreate, "GROUP_CREATE" );
998   createGeomAction( GEOMOp::OpGroupEdit,   "GROUP_EDIT" );
999   createGeomAction( GEOMOp::OpGroupUnion,  "GROUP_UNION" );
1000   createGeomAction( GEOMOp::OpGroupIntersect, "GROUP_INTERSECT" );
1001   createGeomAction( GEOMOp::OpGroupCut,    "GROUP_CUT" );
1002
1003   createGeomAction( GEOMOp::OpCreateField, "FIELD_CREATE" );
1004   createGeomAction( GEOMOp::OpEditField,   "FIELD_EDIT" );
1005
1006   createGeomAction( GEOMOp::OpReimport,    "RELOAD_IMPORTED" );
1007
1008   createGeomAction( GEOMOp::OpQuadFace,    "Q_FACE" );
1009   createGeomAction( GEOMOp::OpHexaSolid,   "HEX_SOLID" );
1010
1011   createGeomAction( GEOMOp::Op2dSketcher,  "SKETCH" );
1012   createGeomAction( GEOMOp::Op3dSketcher,  "3DSKETCH" );
1013   createGeomAction( GEOMOp::OpExplode,     "EXPLODE" );
1014 #ifdef WITH_OPENCV
1015   createGeomAction( GEOMOp::OpFeatureDetect,"FEATURE_DETECTION" );
1016 #endif
1017   createGeomAction( GEOMOp::OpPictureImport,"PICTURE_IMPORT" );
1018   createGeomAction( GEOMOp::Op2dPolylineEditor, "CURVE_CREATOR" );
1019
1020   createGeomAction( GEOMOp::OpEdge,        "EDGE" );
1021   createGeomAction( GEOMOp::OpWire,        "WIRE" );
1022   createGeomAction( GEOMOp::OpFace,        "FACE" );
1023   createGeomAction( GEOMOp::OpShell,       "SHELL" );
1024   createGeomAction( GEOMOp::OpSolid,       "SOLID" );
1025   createGeomAction( GEOMOp::OpCompound,    "COMPOUND" );
1026
1027   createGeomAction( GEOMOp::OpFuse,        "FUSE" );
1028   createGeomAction( GEOMOp::OpCommon,      "COMMON" );
1029   createGeomAction( GEOMOp::OpCut,         "CUT" );
1030   createGeomAction( GEOMOp::OpSection,     "SECTION" );
1031
1032   createGeomAction( GEOMOp::OpTranslate,      "TRANSLATION" );
1033   createGeomAction( GEOMOp::OpRotate,         "ROTATION" );
1034   createGeomAction( GEOMOp::OpChangeLoc,      "MODIFY_LOCATION" );
1035   createGeomAction( GEOMOp::OpMirror,         "MIRROR" );
1036   createGeomAction( GEOMOp::OpScale,          "SCALE" );
1037   createGeomAction( GEOMOp::OpOffset,         "OFFSET" );
1038   createGeomAction( GEOMOp::OpProjection,     "PROJECTION" );
1039   createGeomAction( GEOMOp::OpProjOnCyl,      "PROJ_ON_CYL" );
1040   createGeomAction( GEOMOp::OpMultiTranslate, "MUL_TRANSLATION" );
1041   createGeomAction( GEOMOp::OpMultiRotate,    "MUL_ROTATION" );
1042   createGeomAction( GEOMOp::OpExtension,      "EXTENSION" );
1043
1044   createGeomAction( GEOMOp::OpPartition,      "PARTITION" );
1045   createGeomAction( GEOMOp::OpArchimede,      "ARCHIMEDE" );
1046   createGeomAction( GEOMOp::OpFillet3d,       "FILLET" );
1047   createGeomAction( GEOMOp::OpChamfer,        "CHAMFER" );
1048   createGeomAction( GEOMOp::OpShapesOnShape,  "GET_SHAPES_ON_SHAPE" );
1049   createGeomAction( GEOMOp::OpSharedShapes,   "GET_SHARED_SHAPES" );
1050   createGeomAction( GEOMOp::OpTransferData,   "TRANSFER_DATA" );
1051   createGeomAction( GEOMOp::OpExtraction,     "EXTRACTION" );
1052   createGeomAction( GEOMOp::OpExtrudedCut,    "EXTRUDED_CUT" );
1053   createGeomAction( GEOMOp::OpExtrudedBoss,   "EXTRUDED_BOSS" );
1054   createGeomAction( GEOMOp::OpFillet1d,       "FILLET_1D" );
1055   createGeomAction( GEOMOp::OpFillet2d,       "FILLET_2D" );
1056
1057   createGeomAction( GEOMOp::OpMultiTransform, "MUL_TRANSFORM" );
1058   createGeomAction( GEOMOp::OpExplodeBlock,   "EXPLODE_BLOCKS" );
1059   createGeomAction( GEOMOp::OpPropagate,      "PROPAGATE" );
1060
1061   createGeomAction( GEOMOp::OpSewing,           "SEWING" );
1062   createGeomAction( GEOMOp::OpGlueFaces,        "GLUE_FACES" );
1063   createGeomAction( GEOMOp::OpGlueEdges,        "GLUE_EDGES" );
1064   createGeomAction( GEOMOp::OpLimitTolerance,   "LIMIT_TOLERANCE" );
1065   createGeomAction( GEOMOp::OpSuppressFaces,    "SUPPRESS_FACES" );
1066   createGeomAction( GEOMOp::OpSuppressHoles,    "SUPPERSS_HOLES" );
1067   createGeomAction( GEOMOp::OpShapeProcess,     "SHAPE_PROCESS" );
1068   createGeomAction( GEOMOp::OpCloseContour,     "CLOSE_CONTOUR" );
1069   createGeomAction( GEOMOp::OpRemoveIntWires,   "SUPPRESS_INT_WIRES" );
1070   createGeomAction( GEOMOp::OpAddPointOnEdge,   "POINT_ON_EDGE" );
1071   createGeomAction( GEOMOp::OpFreeBoundaries,   "CHECK_FREE_BNDS" );
1072   createGeomAction( GEOMOp::OpFreeFaces,        "CHECK_FREE_FACES" );
1073   createGeomAction( GEOMOp::OpOrientation,      "CHANGE_ORIENTATION" );
1074   createGeomAction( GEOMOp::OpRemoveWebs,       "REMOVE_WEBS" );
1075   createGeomAction( GEOMOp::OpRemoveExtraEdges, "REMOVE_EXTRA_EDGES" );
1076   createGeomAction( GEOMOp::OpFuseEdges,        "FUSE_EDGES" );
1077   createGeomAction( GEOMOp::OpUnionFaces,       "UNION_FACES" );
1078   createGeomAction( GEOMOp::OpInspectObj,       "INSPECT_OBJECT" );
1079
1080   createGeomAction( GEOMOp::OpPointCoordinates, "POINT_COORDS" );
1081   createGeomAction( GEOMOp::OpProperties,       "BASIC_PROPS" );
1082   createGeomAction( GEOMOp::OpCenterMass,       "MASS_CENTER" );
1083   createGeomAction( GEOMOp::OpInertia,          "INERTIA" );
1084   createGeomAction( GEOMOp::OpNormale,          "NORMALE" );
1085   createGeomAction( GEOMOp::OpBoundingBox,      "BND_BOX" );
1086   createGeomAction( GEOMOp::OpMinDistance,      "MIN_DIST" );
1087   createGeomAction( GEOMOp::OpAngle,            "MEASURE_ANGLE" );
1088   createGeomAction( GEOMOp::OpManageDimensions, "MANAGE_DIMENSIONS" );
1089   createGeomAction( GEOMOp::OpAnnotation,       "ANNOTATION" );
1090   createGeomAction( GEOMOp::OpEditAnnotation,   "EDIT_ANNOTATION" );
1091   createGeomAction( GEOMOp::OpDeleteAnnotation, "DELETE_ANNOTATION" );
1092
1093   createGeomAction( GEOMOp::OpTolerance,        "TOLERANCE" );
1094   createGeomAction( GEOMOp::OpWhatIs,           "WHAT_IS" );
1095   createGeomAction( GEOMOp::OpCheckShape,       "CHECK" );
1096   createGeomAction( GEOMOp::OpCheckCompound,    "CHECK_COMPOUND" );
1097   createGeomAction( GEOMOp::OpGetNonBlocks,     "GET_NON_BLOCKS" );
1098   createGeomAction( GEOMOp::OpCheckSelfInters,  "CHECK_SELF_INTERSECTIONS" );
1099   createGeomAction( GEOMOp::OpFastCheckInters,  "FAST_CHECK_INTERSECTIONS" );
1100 #ifndef DISABLE_PLOT2DVIEWER
1101   createGeomAction( GEOMOp::OpShapeStatistics,  "SHAPE_STATISTICS" );
1102 #endif
1103
1104 #ifndef DISABLE_PYCONSOLE
1105 #ifdef _DEBUG_ // PAL16821
1106   createGeomAction( GEOMOp::OpCheckGeom,        "CHECK_GEOMETRY" );
1107 #endif
1108 #endif
1109
1110   createGeomAction( GEOMOp::OpMaterialsLibrary,   "MATERIALS_LIBRARY" );
1111   createGeomAction( GEOMOp::OpDMWireframe,        "WIREFRAME" );
1112   createGeomAction( GEOMOp::OpDMShading,          "SHADING" );
1113   createGeomAction( GEOMOp::OpDMShadingWithEdges, "SHADING_WITH_EDGES" );
1114   createGeomAction( GEOMOp::OpDMTexture,          "TEXTURE" );
1115   createGeomAction( GEOMOp::OpShowAll,          "DISPLAY_ALL" );
1116   createGeomAction( GEOMOp::OpHideAll,          "ERASE_ALL" );
1117   createGeomAction( GEOMOp::OpShow,             "DISPLAY" );
1118   createGeomAction( GEOMOp::OpSwitchVectors,    "VECTOR_MODE");
1119   createGeomAction( GEOMOp::OpSwitchVertices,   "VERTICES_MODE");
1120   createGeomAction( GEOMOp::OpSwitchName,       "NAME_MODE");
1121   createGeomAction( GEOMOp::OpSelectVertex,     "VERTEX_SEL_ONLY" ,"", 0, true );
1122   createGeomAction( GEOMOp::OpSelectEdge,       "EDGE_SEL_ONLY", "", 0, true );
1123   createGeomAction( GEOMOp::OpSelectWire,       "WIRE_SEL_ONLY", "",  0, true );
1124   createGeomAction( GEOMOp::OpSelectFace,       "FACE_SEL_ONLY", "", 0, true );
1125   createGeomAction( GEOMOp::OpSelectShell,      "SHELL_SEL_ONLY", "",  0, true );
1126   createGeomAction( GEOMOp::OpSelectSolid,      "SOLID_SEL_ONLY", "", 0, true );
1127   createGeomAction( GEOMOp::OpSelectCompound,   "COMPOUND_SEL_ONLY", "",  0, true );
1128   createGeomAction( GEOMOp::OpSelectAll,        "ALL_SEL_ONLY", "",  0, true );
1129   createGeomAction( GEOMOp::OpShowOnly,         "DISPLAY_ONLY" );
1130   createGeomAction( GEOMOp::OpShowOnlyChildren, "SHOW_ONLY_CHILDREN" );
1131   createGeomAction( GEOMOp::OpBringToFront,     "BRING_TO_FRONT", "", 0, true );
1132   createGeomAction( GEOMOp::OpClsBringToFront,  "CLS_BRING_TO_FRONT" );
1133   createGeomAction( GEOMOp::OpHide,             "ERASE" );
1134
1135   createGeomAction( GEOMOp::OpWireframe,        "POP_WIREFRAME", "", 0, true );
1136   createGeomAction( GEOMOp::OpShading,          "POP_SHADING", "", 0, true );
1137   createGeomAction( GEOMOp::OpShadingWithEdges, "POP_SHADING_WITH_EDGES", "", 0, true );
1138   createGeomAction( GEOMOp::OpTexture,          "POP_TEXTURE", "", 0, true );
1139   createGeomAction( GEOMOp::OpEdgeWidth,        "EDGE_WIDTH");
1140   createGeomAction( GEOMOp::OpIsosWidth,        "ISOS_WIDTH");
1141   createGeomAction( GEOMOp::OpVectors,          "POP_VECTORS", "", 0, true );
1142   createGeomAction( GEOMOp::OpVertices,         "POP_VERTICES", "", 0, true );
1143   createGeomAction( GEOMOp::OpShowName,         "POP_SHOW_NAME", "", 0, true );
1144   createGeomAction( GEOMOp::OpDeflection,       "POP_DEFLECTION" );
1145   createGeomAction( GEOMOp::OpColor,            "POP_COLOR" );
1146   createGeomAction( GEOMOp::OpSetTexture,       "POP_SETTEXTURE" );
1147   createGeomAction( GEOMOp::OpTransparency,     "POP_TRANSPARENCY" );
1148   createGeomAction( GEOMOp::OpIsos,             "POP_ISOS" );
1149   createGeomAction( GEOMOp::OpAutoColor,        "POP_AUTO_COLOR" );
1150   createGeomAction( GEOMOp::OpNoAutoColor,      "POP_DISABLE_AUTO_COLOR" );
1151   createGeomAction( GEOMOp::OpGroupCreatePopup, "POP_CREATE_GROUP" );
1152   createGeomAction( GEOMOp::OpEditFieldPopup,   "POP_EDIT_FIELD" );
1153   createGeomAction( GEOMOp::OpDiscloseChildren, "POP_DISCLOSE_CHILDREN" );
1154   createGeomAction( GEOMOp::OpConcealChildren,  "POP_CONCEAL_CHILDREN" );
1155   createGeomAction( GEOMOp::OpUnpublishObject,  "POP_UNPUBLISH_OBJ" );
1156   createGeomAction( GEOMOp::OpPublishObject,    "POP_PUBLISH_OBJ" );
1157   createGeomAction( GEOMOp::OpPointMarker,      "POP_POINT_MARKER" );
1158   createGeomAction( GEOMOp::OpMaterialProperties,   "POP_MATERIAL_PROPERTIES" );
1159   createGeomAction( GEOMOp::OpPredefMaterCustom,    "POP_PREDEF_MATER_CUSTOM" );
1160   createGeomAction( GEOMOp::OpCreateFolder, "POP_CREATE_FOLDER" );
1161   createGeomAction( GEOMOp::OpSortChildren, "POP_SORT_CHILD_ITEMS" );
1162 #ifndef DISABLE_GRAPHICSVIEW
1163   createGeomAction( GEOMOp::OpShowDependencyTree, "POP_SHOW_DEPENDENCY_TREE" );
1164 #endif
1165   createGeomAction( GEOMOp::OpReduceStudy,        "POP_REDUCE_STUDY" );
1166   createGeomAction( GEOMOp::OpShowAllDimensions,  "POP_SHOW_ALL_DIMENSIONS" );
1167   createGeomAction( GEOMOp::OpHideAllDimensions,  "POP_HIDE_ALL_DIMENSIONS" );
1168   createGeomAction( GEOMOp::OpShowAllAnnotations, "POP_SHOW_ALL_ANNOTATIONS" );
1169   createGeomAction( GEOMOp::OpHideAllAnnotations, "POP_HIDE_ALL_ANNOTATIONS" );
1170
1171   // Create actions for increase/decrease transparency shortcuts
1172   createGeomAction( GEOMOp::OpIncrTransparency, "", "", 0, false,
1173                     "Geometry:Increase transparency");
1174   createGeomAction( GEOMOp::OpDecrTransparency, "", "", 0, false,
1175                     "Geometry:Decrease transparency");
1176
1177   // Create actions for increase/decrease number of isolines
1178   createGeomAction( GEOMOp::OpIncrNbIsos, "", "", 0, false,
1179                     "Geometry:Increase number of isolines");
1180   createGeomAction( GEOMOp::OpDecrNbIsos, "", "", 0, false,
1181                     "Geometry:Decrease number of isolines");
1182
1183   //createGeomAction( GEOMOp::OpPipeTShape, "PIPETSHAPE" );
1184   //createGeomAction( GEOMOp::OpDividedDisk, "DIVIDEDDISK" );
1185   //createGeomAction( GEOMOp::OpDividedCylinder, "DIVIDEDCYLINDER" );
1186   //createGeomAction( GEOMOp::OpSmoothingSurface, "SMOOTHINGSURFACE" );
1187   //@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@ do not remove this line @@ do not remove this line @@//
1188
1189   // ---- create menus --------------------------
1190
1191   /*int fileId =*/ createMenu( tr( "MEN_FILE" ), -1, -1 );
1192
1193   int editId = createMenu( tr( "MEN_EDIT" ), -1, -1 );
1194   createMenu( GEOMOp::OpDelete, editId, -1 );
1195
1196   int newEntId = createMenu( tr( "MEN_NEW_ENTITY" ), -1, -1, 10 );
1197
1198   int basicId = createMenu( tr( "MEN_BASIC" ), newEntId, -1 );
1199   createMenu( GEOMOp::OpPoint,            basicId, -1 );
1200   createMenu( GEOMOp::OpLine,             basicId, -1 );
1201   createMenu( GEOMOp::OpCircle,           basicId, -1 );
1202   createMenu( GEOMOp::OpEllipse,          basicId, -1 );
1203   createMenu( GEOMOp::OpArc,              basicId, -1 );
1204   createMenu( GEOMOp::OpCurve,            basicId, -1 );
1205   createMenu( GEOMOp::Op2dSketcher,       basicId, -1 );
1206   createMenu( GEOMOp::Op2dPolylineEditor, basicId, -1 );
1207   createMenu( GEOMOp::Op3dSketcher,       basicId, -1 );
1208   createMenu( GEOMOp::OpIsoline,          basicId, -1 );
1209   createMenu( GEOMOp::OpSurfaceFromFace, basicId, -1 );
1210   createMenu( separator(),                basicId, -1 );
1211   createMenu( GEOMOp::OpVector,           basicId, -1 );
1212   createMenu( GEOMOp::OpPlane,            basicId, -1 );
1213   createMenu( GEOMOp::OpLCS,              basicId, -1 );
1214   createMenu( GEOMOp::OpOriginAndVectors, basicId, -1 );
1215
1216   int primId = createMenu( tr( "MEN_PRIMITIVES" ), newEntId, -1 );
1217   createMenu( GEOMOp::OpBox,       primId, -1 );
1218   createMenu( GEOMOp::OpCylinder,  primId, -1 );
1219   createMenu( GEOMOp::OpSphere,    primId, -1 );
1220   createMenu( GEOMOp::OpTorus,     primId, -1 );
1221   createMenu( GEOMOp::OpCone,      primId, -1 );
1222   createMenu( GEOMOp::OpRectangle, primId, -1 );
1223   createMenu( GEOMOp::OpDisk,      primId, -1 );
1224   //createMenu( GEOMOp::OpPipeTShape,primId, -1 );
1225
1226   int genId = createMenu( tr( "MEN_GENERATION" ), newEntId, -1 );
1227   createMenu( GEOMOp::OpPrism,      genId, -1 );
1228   createMenu( GEOMOp::OpRevolution, genId, -1 );
1229   createMenu( GEOMOp::OpFilling,    genId, -1 );
1230   createMenu( GEOMOp::OpPipe,       genId, -1 );
1231   createMenu( GEOMOp::OpPipePath,   genId, -1 );
1232   createMenu( GEOMOp::OpThickness,  genId, -1 );
1233
1234   //int advId = createMenu( tr( "MEN_ADVANCED" ), newEntId, -1 );
1235   //createMenu( GEOMOp::OpSmoothingSurface, advId, -1 );
1236   //@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@ do not remove this line @@ do not remove this line @@//
1237
1238   createMenu( separator(), newEntId, -1 );
1239
1240   int groupId = createMenu( tr( "MEN_GROUP" ), newEntId, -1 );
1241   createMenu( GEOMOp::OpGroupCreate,    groupId, -1 );
1242   createMenu( GEOMOp::OpGroupEdit,      groupId, -1 );
1243   createMenu( GEOMOp::OpGroupUnion,     groupId, -1 );
1244   createMenu( GEOMOp::OpGroupIntersect, groupId, -1 );
1245   createMenu( GEOMOp::OpGroupCut,       groupId, -1 );
1246
1247   createMenu( separator(), newEntId, -1 );
1248
1249   int fieldId = createMenu( tr( "MEN_FIELD" ), newEntId, -1 );
1250   createMenu( GEOMOp::OpCreateField,    fieldId, -1 );
1251   createMenu( GEOMOp::OpEditField,      fieldId, -1 );
1252
1253   createMenu( separator(), newEntId, -1 );
1254
1255   int blocksId = createMenu( tr( "MEN_BLOCKS" ), newEntId, -1 );
1256   createMenu( GEOMOp::OpQuadFace,        blocksId, -1 );
1257   createMenu( GEOMOp::OpHexaSolid,       blocksId, -1 );
1258   //createMenu( GEOMOp::OpDividedDisk,     blocksId, -1 );
1259   //createMenu( GEOMOp::OpDividedCylinder, blocksId, -1 );
1260
1261   createMenu( separator(),          newEntId, -1 );
1262
1263   createMenu( GEOMOp::OpExplode,    newEntId, -1 );
1264
1265   int buildId = createMenu( tr( "MEN_BUILD" ), newEntId, -1 );
1266   createMenu( GEOMOp::OpEdge,     buildId, -1 );
1267   createMenu( GEOMOp::OpWire,     buildId, -1 );
1268   createMenu( GEOMOp::OpFace,     buildId, -1 );
1269   createMenu( GEOMOp::OpShell,    buildId, -1 );
1270   createMenu( GEOMOp::OpSolid,    buildId, -1 );
1271   createMenu( GEOMOp::OpCompound, buildId, -1 );
1272
1273   createMenu( separator(),          newEntId, -1 );
1274
1275   createMenu( GEOMOp::OpPictureImport, newEntId, -1 );
1276 #ifdef WITH_OPENCV
1277   createMenu( GEOMOp::OpFeatureDetect, newEntId, -1 );
1278 #endif
1279
1280   int operId = createMenu( tr( "MEN_OPERATIONS" ), -1, -1, 10 );
1281
1282   int boolId = createMenu( tr( "MEN_BOOLEAN" ), operId, -1 );
1283   createMenu( GEOMOp::OpFuse,    boolId, -1 );
1284   createMenu( GEOMOp::OpCommon,  boolId, -1 );
1285   createMenu( GEOMOp::OpCut,     boolId, -1 );
1286   createMenu( GEOMOp::OpSection, boolId, -1 );
1287
1288   int transId = createMenu( tr( "MEN_TRANSFORMATION" ), operId, -1 );
1289   createMenu( GEOMOp::OpTranslate,      transId, -1 );
1290   createMenu( GEOMOp::OpRotate,         transId, -1 );
1291   createMenu( GEOMOp::OpChangeLoc,      transId, -1 );
1292   createMenu( GEOMOp::OpMirror,         transId, -1 );
1293   createMenu( GEOMOp::OpScale,          transId, -1 );
1294   createMenu( GEOMOp::OpOffset,         transId, -1 );
1295   createMenu( GEOMOp::OpProjection,     transId, -1 );
1296   createMenu( GEOMOp::OpExtension,      transId, -1 );
1297   createMenu( GEOMOp::OpProjOnCyl,      transId, -1 );
1298   createMenu( separator(),              transId, -1 );
1299   createMenu( GEOMOp::OpMultiTranslate, transId, -1 );
1300   createMenu( GEOMOp::OpMultiRotate,    transId, -1 );
1301
1302   int blockId = createMenu( tr( "MEN_BLOCKS" ), operId, -1 );
1303   createMenu( GEOMOp::OpMultiTransform, blockId, -1 );
1304   createMenu( GEOMOp::OpExplodeBlock,   blockId, -1 );
1305   createMenu( GEOMOp::OpPropagate,      blockId, -1 );
1306
1307   createMenu( separator(), operId, -1 );
1308
1309   createMenu( GEOMOp::OpPartition,     operId, -1 );
1310   createMenu( GEOMOp::OpArchimede,     operId, -1 );
1311   createMenu( GEOMOp::OpShapesOnShape, operId, -1 );
1312   createMenu( GEOMOp::OpSharedShapes,  operId, -1 );
1313   createMenu( GEOMOp::OpTransferData,  operId, -1 );
1314   createMenu( GEOMOp::OpExtraction,    operId, -1 );
1315
1316   createMenu( separator(), operId, -1 );
1317
1318   createMenu( GEOMOp::OpFillet1d,      operId, -1 );
1319   createMenu( GEOMOp::OpFillet2d,      operId, -1 );
1320   createMenu( GEOMOp::OpFillet3d,      operId, -1 );
1321   createMenu( GEOMOp::OpChamfer,       operId, -1 );
1322   createMenu( GEOMOp::OpExtrudedBoss,  operId, -1 );
1323   createMenu( GEOMOp::OpExtrudedCut,   operId, -1 );
1324
1325   int repairId = createMenu( tr( "MEN_REPAIR" ), -1, -1, 10 );
1326   createMenu( GEOMOp::OpShapeProcess,    repairId, -1 );
1327   createMenu( GEOMOp::OpSuppressFaces,   repairId, -1 );
1328   createMenu( GEOMOp::OpCloseContour,    repairId, -1 );
1329   createMenu( GEOMOp::OpRemoveIntWires,  repairId, -1 );
1330   createMenu( GEOMOp::OpSuppressHoles,   repairId, -1 );
1331   createMenu( GEOMOp::OpSewing,          repairId, -1 );
1332   createMenu( GEOMOp::OpGlueFaces,       repairId, -1 );
1333   createMenu( GEOMOp::OpGlueEdges,       repairId, -1 );
1334   createMenu( GEOMOp::OpLimitTolerance,  repairId, -1 );
1335   createMenu( GEOMOp::OpAddPointOnEdge,  repairId, -1 );
1336   //createMenu( GEOMOp::OpFreeBoundaries,  repairId, -1 );
1337   //createMenu( GEOMOp::OpFreeFaces,       repairId, -1 );
1338   createMenu( GEOMOp::OpOrientation,      repairId, -1 );
1339   createMenu( GEOMOp::OpRemoveWebs,       repairId, -1 );
1340   createMenu( GEOMOp::OpRemoveExtraEdges, repairId, -1 );
1341   createMenu( GEOMOp::OpFuseEdges,        repairId, -1 );
1342   createMenu( GEOMOp::OpUnionFaces,       repairId, -1 );
1343
1344   int measurId = createMenu( tr( "MEN_MEASURES" ), -1, -1, 10 );
1345   createMenu( GEOMOp::OpPointCoordinates, measurId, -1 );
1346   createMenu( GEOMOp::OpProperties,       measurId, -1 );
1347   createMenu( separator(),                measurId, -1 );
1348   createMenu( GEOMOp::OpCenterMass,       measurId, -1 );
1349   createMenu( GEOMOp::OpInertia,          measurId, -1 );
1350   createMenu( GEOMOp::OpNormale,          measurId, -1 );
1351   createMenu( separator(),                measurId, -1 );
1352   createMenu( GEOMOp::OpFreeBoundaries,   measurId, -1 );
1353   createMenu( GEOMOp::OpFreeFaces,        measurId, -1 );
1354   createMenu( separator(),                measurId, -1 );
1355
1356   int dimId = createMenu( tr( "MEN_DIMENSIONS" ), measurId, -1 );
1357   createMenu( GEOMOp::OpBoundingBox,      dimId, -1 );
1358   createMenu( GEOMOp::OpMinDistance,      dimId, -1 );
1359   createMenu( GEOMOp::OpAngle,            dimId, -1 );
1360   createMenu( GEOMOp::OpManageDimensions, dimId, -1 );
1361
1362   createMenu( GEOMOp::OpAnnotation,       measurId, -1 );
1363
1364   createMenu( separator(),               measurId, -1 );
1365   createMenu( GEOMOp::OpTolerance,       measurId, -1 );
1366   createMenu( separator(),               measurId, -1 );
1367   createMenu( GEOMOp::OpWhatIs,          measurId, -1 );
1368   createMenu( GEOMOp::OpCheckShape,      measurId, -1 );
1369   createMenu( GEOMOp::OpCheckCompound,   measurId, -1 );
1370   createMenu( GEOMOp::OpGetNonBlocks,    measurId, -1 );
1371   createMenu( GEOMOp::OpCheckSelfInters, measurId, -1 );
1372   createMenu( GEOMOp::OpFastCheckInters, measurId, -1 );
1373   createMenu( GEOMOp::OpInspectObj,      measurId, -1 );
1374 #ifndef DISABLE_PLOT2DVIEWER
1375   createMenu( GEOMOp::OpShapeStatistics, measurId, -1 );
1376 #endif
1377
1378   int toolsId = createMenu( tr( "MEN_TOOLS" ), -1, -1, 50 );
1379 #ifndef DISABLE_PYCONSOLE
1380 #if defined(_DEBUG_) || defined(_DEBUG) // PAL16821
1381   createMenu( separator(),         toolsId, -1 );
1382   createMenu( GEOMOp::OpCheckGeom, toolsId, -1 );
1383 #endif
1384 #endif
1385
1386   createMenu( separator(),         toolsId, -1 );
1387   createMenu( GEOMOp::OpMaterialsLibrary, toolsId, -1 );
1388   createMenu( separator(),         toolsId, -1 );
1389
1390   int viewId = createMenu( tr( "MEN_VIEW" ), -1, -1 );
1391   createMenu( separator(),       viewId, -1 );
1392
1393   int dispmodeId = createMenu( tr( "MEN_DISPLAY_MODE" ), viewId, -1 );
1394   createMenu( GEOMOp::OpDMWireframe,        dispmodeId, -1 );
1395   createMenu( GEOMOp::OpDMShading,          dispmodeId, -1 );
1396   createMenu( GEOMOp::OpDMShadingWithEdges, dispmodeId, -1 );
1397   createMenu( GEOMOp::OpDMTexture,          dispmodeId, -1 );
1398   createMenu( separator(),                  dispmodeId, -1 );
1399   createMenu( GEOMOp::OpSwitchVectors,      dispmodeId, -1 );
1400   createMenu( GEOMOp::OpSwitchVertices,     dispmodeId, -1 );
1401   createMenu( GEOMOp::OpSwitchName,         dispmodeId, -1 );
1402
1403   createMenu( separator(),       viewId, -1 );
1404   createMenu( GEOMOp::OpShowAll, viewId, -1 );
1405   createMenu( GEOMOp::OpHideAll, viewId, -1 );
1406   createMenu( separator(),       viewId, -1 );
1407   createMenu( GEOMOp::OpPublishObject, viewId, -1 );
1408   createMenu( separator(),       viewId, -1 );
1409
1410 /*
1411   PAL9111:
1412   because of these items are accessible through object browser and viewers
1413   we have removed they from main menu
1414
1415   createMenu( GEOMOp::OpShow, viewId, -1 );
1416   createMenu( GEOMOp::OpShowOnly, viewId, -1 );
1417   createMenu( GEOMOp::OpHide, viewId, -1 );
1418 */
1419
1420   // ---- create toolbars --------------------------
1421
1422   int basicTbId = createTool( tr( "TOOL_BASIC" ), QString( "GEOMBasic" ) );
1423   createTool( GEOMOp::OpPoint,            basicTbId );
1424   createTool( GEOMOp::OpLine,             basicTbId );
1425   createTool( GEOMOp::OpCircle,           basicTbId );
1426   createTool( GEOMOp::OpEllipse,          basicTbId );
1427   createTool( GEOMOp::OpArc,              basicTbId );
1428   createTool( GEOMOp::OpCurve,            basicTbId );
1429   createTool( GEOMOp::OpVector,           basicTbId );
1430   createTool( GEOMOp::Op2dSketcher,       basicTbId ); //rnc
1431   createTool( GEOMOp::Op2dPolylineEditor, basicTbId ); 
1432   createTool( GEOMOp::Op3dSketcher,       basicTbId ); //rnc
1433   createTool( GEOMOp::OpIsoline,          basicTbId );
1434   createTool( GEOMOp::OpSurfaceFromFace,  basicTbId );
1435   createTool( GEOMOp::OpPlane,            basicTbId );
1436   createTool( GEOMOp::OpLCS,              basicTbId );
1437   createTool( GEOMOp::OpOriginAndVectors, basicTbId );
1438
1439 //   int sketchTbId = createTool( tr( "TOOL_SKETCH" ), QString( "GEOMSketch" ) );
1440 //   createTool( GEOMOp::Op2dSketcher,  sketchTbId );
1441 //   createTool( GEOMOp::Op3dSketcher,  sketchTbId );
1442
1443   int primTbId = createTool( tr( "TOOL_PRIMITIVES" ), QString( "GEOMPrimitives" ) );
1444   createTool( GEOMOp::OpBox,        primTbId );
1445   createTool( GEOMOp::OpCylinder,   primTbId );
1446   createTool( GEOMOp::OpSphere,     primTbId );
1447   createTool( GEOMOp::OpTorus,      primTbId );
1448   createTool( GEOMOp::OpCone,       primTbId );
1449   createTool( GEOMOp::OpRectangle,  primTbId );
1450   createTool( GEOMOp::OpDisk,       primTbId );
1451   //createTool( GEOMOp::OpPipeTShape, primTbId ); //rnc
1452
1453   //int blocksTbId = createTool( tr( "TOOL_BLOCKS" ), QString( "GEOMBlocks" ) );
1454   //createTool( GEOMOp::OpDividedDisk, blocksTbId );
1455   //createTool( GEOMOp::OpDividedCylinder, blocksTbId );
1456
1457   int boolTbId = createTool( tr( "TOOL_BOOLEAN" ), QString( "GEOMBooleanOperations" ) );
1458   createTool( GEOMOp::OpFuse,       boolTbId );
1459   createTool( GEOMOp::OpCommon,     boolTbId );
1460   createTool( GEOMOp::OpCut,        boolTbId );
1461   createTool( GEOMOp::OpSection,    boolTbId );
1462
1463   int genTbId = createTool( tr( "TOOL_GENERATION" ), QString( "GEOMGeneration" ) );
1464   createTool( GEOMOp::OpPrism,      genTbId );
1465   createTool( GEOMOp::OpRevolution, genTbId );
1466   createTool( GEOMOp::OpFilling,    genTbId );
1467   createTool( GEOMOp::OpPipe,       genTbId );
1468   createTool( GEOMOp::OpPipePath,   genTbId );
1469   createTool( GEOMOp::OpThickness,  genTbId );
1470
1471   int transTbId = createTool( tr( "TOOL_TRANSFORMATION" ), QString( "GEOMTransformation" ) );
1472   createTool( GEOMOp::OpTranslate,      transTbId );
1473   createTool( GEOMOp::OpRotate,         transTbId );
1474   createTool( GEOMOp::OpChangeLoc,      transTbId );
1475   createTool( GEOMOp::OpMirror,         transTbId );
1476   createTool( GEOMOp::OpScale,          transTbId );
1477   createTool( GEOMOp::OpOffset,         transTbId );
1478   createTool( GEOMOp::OpProjection,     transTbId );
1479   createTool( GEOMOp::OpExtension,      transTbId );
1480   createTool( GEOMOp::OpProjOnCyl,      transTbId );
1481   createTool( separator(),              transTbId );
1482   createTool( GEOMOp::OpMultiTranslate, transTbId );
1483   createTool( GEOMOp::OpMultiRotate,    transTbId );
1484
1485   int operTbId = createTool( tr( "TOOL_OPERATIONS" ), QString( "GEOMOperations" ) );
1486   createTool( GEOMOp::OpExplode,         operTbId );
1487   createTool( GEOMOp::OpPartition,       operTbId );
1488   createTool( GEOMOp::OpArchimede,       operTbId );
1489   createTool( GEOMOp::OpShapesOnShape,   operTbId );
1490   createTool( GEOMOp::OpSharedShapes,    operTbId );
1491   createTool( GEOMOp::OpTransferData,    operTbId );
1492   createTool( GEOMOp::OpExtraction,      operTbId );
1493
1494   int featTbId = createTool( tr( "TOOL_FEATURES" ), QString( "GEOMModification" ) );
1495   createTool( GEOMOp::OpFillet1d,        featTbId );
1496   createTool( GEOMOp::OpFillet2d,        featTbId );
1497   createTool( GEOMOp::OpFillet3d,        featTbId );
1498   createTool( GEOMOp::OpChamfer,         featTbId );
1499   createTool( GEOMOp::OpExtrudedBoss,    featTbId );
1500   createTool( GEOMOp::OpExtrudedCut,     featTbId );
1501
1502   int buildTbId = createTool( tr( "TOOL_BUILD" ), QString( "GEOMBuild" ) );
1503   createTool( GEOMOp::OpEdge,     buildTbId );
1504   createTool( GEOMOp::OpWire,     buildTbId );
1505   createTool( GEOMOp::OpFace,     buildTbId );
1506   createTool( GEOMOp::OpShell,    buildTbId );
1507   createTool( GEOMOp::OpSolid,    buildTbId );
1508   createTool( GEOMOp::OpCompound, buildTbId );
1509
1510   int measureTbId = createTool( tr( "TOOL_MEASURES" ), QString( "GEOMMeasures" ) );
1511   createTool( GEOMOp::OpPointCoordinates, measureTbId );
1512   createTool( GEOMOp::OpProperties,       measureTbId );
1513   createTool( GEOMOp::OpCenterMass,       measureTbId );
1514   createTool( GEOMOp::OpInertia,          measureTbId );
1515   createTool( GEOMOp::OpNormale,          measureTbId );
1516   createTool( separator(),                measureTbId );
1517   createTool( GEOMOp::OpBoundingBox,      measureTbId );
1518   createTool( GEOMOp::OpMinDistance,      measureTbId );
1519   createTool( GEOMOp::OpAngle,            measureTbId );
1520   createTool( GEOMOp::OpAnnotation,       measureTbId );
1521   createTool( GEOMOp::OpTolerance  ,      measureTbId );
1522   createTool( separator(),                measureTbId );
1523   createTool( GEOMOp::OpFreeBoundaries,   measureTbId );
1524   createTool( GEOMOp::OpFreeFaces,        measureTbId );
1525   createTool( separator(),                measureTbId );
1526   createTool( GEOMOp::OpWhatIs,           measureTbId );
1527   createTool( GEOMOp::OpCheckShape,       measureTbId );
1528   createTool( GEOMOp::OpCheckCompound,    measureTbId );
1529   createTool( GEOMOp::OpGetNonBlocks,     measureTbId );
1530   createTool( GEOMOp::OpCheckSelfInters,  measureTbId );
1531   createTool( GEOMOp::OpFastCheckInters,  measureTbId );
1532
1533   int picturesTbId = createTool( tr( "TOOL_PICTURES" ), QString( "GEOMPictures" ) );
1534   createTool( GEOMOp::OpPictureImport,    picturesTbId );
1535 #ifdef WITH_OPENCV
1536   createTool( GEOMOp::OpFeatureDetect,  picturesTbId );
1537 #endif
1538
1539   //int advancedTbId = createTool( tr( "TOOL_ADVANCED" ) );
1540   //createTool( GEOMOp::OpSmoothingSurface, advancedTbId );
1541   //@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@ do not remove this line @@ do not remove this line @@//
1542
1543   // ---- create popup menus --------------------------
1544
1545   QString clientOCCorVTK = "(client='OCCViewer' or client='VTKViewer')";
1546   QString clientOCC = "(client='OCCViewer')";
1547   QString clientOCCorVTK_AndSomeVisible = clientOCCorVTK + " and selcount>0 and isVisible";
1548   QString clientOCC_AndSomeVisible = clientOCC + " and selcount>0 and isVisible";
1549
1550   QString clientOCCorOB = "(client='ObjectBrowser' or client='OCCViewer')";
1551   QString clientOCCorVTKorOB = "(client='ObjectBrowser' or client='OCCViewer' or client='VTKViewer')";
1552   QString clientOCCorVTKorOB_AndSomeVisible = clientOCCorVTKorOB + " and selcount>0 and isVisible";
1553   QString clientOCCorOB_AndSomeVisible = clientOCCorOB + " and selcount>0 and isVisible";
1554
1555   QString autoColorPrefix =
1556     "(client='ObjectBrowser' or client='OCCViewer' or client='VTKViewer') and type='Shape' and selcount=1";
1557
1558   QtxPopupMgr* mgr = popupMgr();
1559
1560   mgr->insert( action(  GEOMOp::OpDelete ), -1, -1 );  // delete
1561   mgr->setRule( action( GEOMOp::OpDelete ), QString("$type in {'Shape' 'Group' 'Folder' 'Field' 'FieldStep'} and selcount>0"), QtxPopupMgr::VisibleRule );
1562   mgr->insert( action(  GEOMOp::OpGroupCreatePopup ), -1, -1 ); // create group
1563   mgr->setRule( action( GEOMOp::OpGroupCreatePopup ), QString("type='Shape' and selcount=1 and isOCC=true"), QtxPopupMgr::VisibleRule );
1564   mgr->insert( action(  GEOMOp::OpEditFieldPopup ), -1, -1 ); // edit field
1565   mgr->setRule( action( GEOMOp::OpEditFieldPopup ), QString("(type='Field' or type='FieldStep') and isOCC=true"), QtxPopupMgr::VisibleRule );
1566   mgr->insert( action(  GEOMOp::OpDiscloseChildren ), -1, -1 ); // disclose child items
1567   mgr->setRule( action( GEOMOp::OpDiscloseChildren ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and hasConcealedChildren=true"), QtxPopupMgr::VisibleRule );
1568
1569   mgr->insert( action(  GEOMOp::OpConcealChildren ), -1, -1 ); // conceal child items
1570   mgr->setRule( action( GEOMOp::OpConcealChildren ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and hasDisclosedChildren=true"), QtxPopupMgr::VisibleRule );
1571   mgr->insert( action(  GEOMOp::OpGroupEdit ), -1, -1 );  // edit group
1572   mgr->setRule( action( GEOMOp::OpGroupEdit ),  QString("client='ObjectBrowser' and type='Group' and selcount=1 and isOCC=true"), QtxPopupMgr::VisibleRule );
1573   mgr->insert( separator(), -1, -1 );     // -----------
1574
1575   //QString bringRule = clientOCCorOB + " and ($component={'GEOM'}) and (selcount>0) and isOCC=true and topLevel=false";
1576   QString bringRule = clientOCCorOB + " and ($component={'GEOM'}) and isFolder=false and (selcount>0) and isOCC=true";
1577   mgr->insert( action(GEOMOp::OpBringToFront ), -1, -1 ); // bring to front
1578   mgr->setRule(action(GEOMOp::OpBringToFront), bringRule + " and autoBringToFront = false", QtxPopupMgr::VisibleRule );
1579   mgr->setRule(action(GEOMOp::OpBringToFront), "topLevel=true", QtxPopupMgr::ToggleRule );
1580   mgr->insert( action(GEOMOp::OpClsBringToFront ), -1, -1 ); // clear bring to front
1581   mgr->setRule( action(GEOMOp::OpClsBringToFront ), clientOCC + " and autoBringToFront = false", QtxPopupMgr::VisibleRule );
1582   mgr->insert( separator(), -1, -1 );     // -----------
1583   dispmodeId = mgr->insert(  tr( "MEN_DISPLAY_MODE" ), -1, -1 ); // display mode menu
1584   mgr->insert( action(  GEOMOp::OpWireframe ), dispmodeId, -1 ); // wireframe
1585   mgr->setRule( action( GEOMOp::OpWireframe ), clientOCCorVTK_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1586   mgr->setRule( action( GEOMOp::OpWireframe ), clientOCCorVTK + " and displaymode='Wireframe'", QtxPopupMgr::ToggleRule );
1587   mgr->insert( action(  GEOMOp::OpShading ), dispmodeId, -1 ); // shading
1588   mgr->setRule( action( GEOMOp::OpShading ), clientOCCorVTK_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1589   mgr->setRule( action( GEOMOp::OpShading ), clientOCCorVTK + " and displaymode='Shading'", QtxPopupMgr::ToggleRule );
1590   mgr->insert( action(  GEOMOp::OpShadingWithEdges ), dispmodeId, -1 ); // shading with edges
1591   mgr->setRule( action( GEOMOp::OpShadingWithEdges ), clientOCCorVTK_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1592   mgr->setRule( action( GEOMOp::OpShadingWithEdges ), clientOCCorVTK + " and displaymode='ShadingWithEdges'", QtxPopupMgr::ToggleRule );
1593   mgr->insert( action(  GEOMOp::OpTexture ), dispmodeId, -1 ); // wireframe
1594   mgr->setRule( action( GEOMOp::OpTexture ), clientOCC_AndSomeVisible, QtxPopupMgr::VisibleRule );
1595   mgr->setRule( action( GEOMOp::OpTexture), clientOCC + " and displaymode='Texture'", QtxPopupMgr::ToggleRule );
1596   mgr->insert( separator(), dispmodeId, -1 );
1597   mgr->insert( action(  GEOMOp::OpVectors ), dispmodeId, -1 ); // vectors
1598   mgr->setRule( action( GEOMOp::OpVectors ), clientOCCorVTK_AndSomeVisible  + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1599   mgr->setRule( action( GEOMOp::OpVectors ), clientOCCorVTK + " and isVectorsMode", QtxPopupMgr::ToggleRule );
1600   mgr->insert( action(  GEOMOp::OpVertices ), dispmodeId, -1 ); // vertices
1601   mgr->setRule( action( GEOMOp::OpVertices ), clientOCCorVTK_AndSomeVisible  + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1602   mgr->setRule( action( GEOMOp::OpVertices ), clientOCCorVTK + " and isVerticesMode", QtxPopupMgr::ToggleRule );
1603   mgr->insert( action(  GEOMOp::OpShowName ), dispmodeId, -1 ); // show name
1604   mgr->setRule( action( GEOMOp::OpShowName ), clientOCCorVTK_AndSomeVisible  + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1605   mgr->setRule( action( GEOMOp::OpShowName ), clientOCCorVTK + " and isNameMode", QtxPopupMgr::ToggleRule );
1606   mgr->insert( separator(), -1, -1 );     // -----------
1607
1608   mgr->insert( action(  GEOMOp::OpColor ), -1, -1 ); // color
1609   mgr->setRule( action( GEOMOp::OpColor ), clientOCCorVTKorOB_AndSomeVisible + " and ($component={'GEOM'})" + "and isPhysicalMaterial=false", QtxPopupMgr::VisibleRule );
1610   mgr->insert( action(  GEOMOp::OpTransparency ), -1, -1 ); // transparency
1611   mgr->setRule( action( GEOMOp::OpTransparency ), clientOCCorVTK_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1612   mgr->insert( action(  GEOMOp::OpIsos ), -1, -1 ); // isos
1613   mgr->setRule( action( GEOMOp::OpIsos ), clientOCCorVTK_AndSomeVisible + " and selcount>0 and isVisible" + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1614   mgr->insert( action(  GEOMOp::OpDeflection ), -1, -1 ); // deflection
1615   mgr->setRule( action( GEOMOp::OpDeflection ), clientOCCorVTK_AndSomeVisible + " and selcount>0 and isVisible" + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1616   mgr->insert( action(  GEOMOp::OpPointMarker ), -1, -1 ); // point marker
1617   mgr->setRule( action( GEOMOp::OpPointMarker ), clientOCCorOB + " and $type in {'Shape' 'Group' 'Field' 'FieldStep'} and selcount>0 and isOCC=true", QtxPopupMgr::VisibleRule );
1618
1619   // material properties
1620   mgr->insert( action(  GEOMOp::OpMaterialProperties ), -1, -1 );
1621   mgr->setRule( action( GEOMOp::OpMaterialProperties ), clientOCCorVTK_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1622
1623  // texture
1624   mgr->insert( action(  GEOMOp::OpSetTexture ), -1, -1 );
1625   mgr->setRule( action( GEOMOp::OpSetTexture ), clientOCCorOB_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1626
1627   int lineW = mgr->insert(  tr( "MEN_LINE_WIDTH" ), -1, -1 ); // line width menu
1628   mgr->insert( action(  GEOMOp::OpEdgeWidth ), lineW, -1 ); // edge width
1629   mgr->setRule( action( GEOMOp::OpEdgeWidth ), clientOCCorVTK_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1630
1631   mgr->insert( action(  GEOMOp::OpIsosWidth ), lineW, -1 ); // isos width
1632   mgr->setRule( action( GEOMOp::OpIsosWidth ), clientOCCorVTK_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1633
1634   mgr->insert( separator(), -1, -1 );     // -----------
1635   mgr->insert( action(  GEOMOp::OpAutoColor ), -1, -1 ); // auto color
1636   mgr->setRule( action( GEOMOp::OpAutoColor ), autoColorPrefix + " and isAutoColor=false", QtxPopupMgr::VisibleRule );
1637   mgr->insert( action(  GEOMOp::OpNoAutoColor ), -1, -1 ); // disable auto color
1638   mgr->setRule( action( GEOMOp::OpNoAutoColor ), autoColorPrefix + " and isAutoColor=true", QtxPopupMgr::VisibleRule );
1639   mgr->insert( separator(), -1, -1 );     // -----------
1640
1641   mgr->insert( action(  GEOMOp::OpEditAnnotation ), -1, -1 );  // edit annotation
1642   mgr->setRule( action( GEOMOp::OpEditAnnotation ),  clientOCC + " and annotationsCount=1", QtxPopupMgr::VisibleRule );
1643   mgr->insert( action(  GEOMOp::OpDeleteAnnotation ), -1, -1 );  // delete annotation
1644   mgr->setRule( action( GEOMOp::OpDeleteAnnotation ),  clientOCC + " and annotationsCount>0", QtxPopupMgr::VisibleRule );
1645   mgr->insert( separator(), -1, -1 );     // -----------
1646
1647   QString canDisplay = "($component={'GEOM'}) and (selcount>0) and ({true} in $canBeDisplayed) ",
1648           onlyComponent = "((type='Component') and selcount=1)",
1649           rule = canDisplay + "and ((($type in {%1}) and( %2 )) or " + onlyComponent + ")",
1650           types = "'Shape' 'Group' 'FieldStep'";
1651
1652   mgr->insert( action(  GEOMOp::OpShow ), -1, -1 ); // display
1653   mgr->setRule( action( GEOMOp::OpShow ), rule.arg( types ).arg( "not isVisible" ), QtxPopupMgr::VisibleRule );
1654
1655   mgr->insert( action(  GEOMOp::OpHide ), -1, -1 ); // erase
1656   mgr->setRule( action( GEOMOp::OpHide ), rule.arg( types ).arg( "isVisible" ), QtxPopupMgr::VisibleRule );
1657
1658   mgr->insert( action(  GEOMOp::OpHideAll ), -1, -1 ); // erase All
1659   mgr->setRule( action( GEOMOp::OpHideAll ), clientOCCorVTK, QtxPopupMgr::VisibleRule );
1660
1661   QString selectOnly = "(client='OCCViewer' or client='VTKViewer') and (selcount=0)";
1662
1663   int selectonlyId = mgr->insert( tr("MEN_SELECT_ONLY"), -1, -1);                //select only menu
1664   mgr->insert( action(GEOMOp::OpSelectVertex),   selectonlyId, -1);                                  //Vertex
1665   mgr->setRule(action(GEOMOp::OpSelectVertex),   selectOnly, QtxPopupMgr::VisibleRule);
1666   mgr->setRule(action(GEOMOp::OpSelectVertex),   selectOnly + " and selectionmode='VERTEX'", QtxPopupMgr::ToggleRule);
1667   mgr->insert( action(GEOMOp::OpSelectEdge),     selectonlyId, -1);                                  //Edge
1668   mgr->setRule(action(GEOMOp::OpSelectEdge),     selectOnly, QtxPopupMgr::VisibleRule);
1669   mgr->setRule(action(GEOMOp::OpSelectEdge),     selectOnly + " and selectionmode='EDGE'", QtxPopupMgr::ToggleRule);
1670   mgr->insert( action(GEOMOp::OpSelectWire),     selectonlyId, -1);                                  //Wire
1671   mgr->setRule(action(GEOMOp::OpSelectWire),     selectOnly, QtxPopupMgr::VisibleRule);
1672   mgr->setRule(action(GEOMOp::OpSelectWire),     selectOnly + " and selectionmode='WIRE'", QtxPopupMgr::ToggleRule);
1673   mgr->insert( action(GEOMOp::OpSelectFace),     selectonlyId, -1);                                  //Face
1674   mgr->setRule(action(GEOMOp::OpSelectFace),     selectOnly, QtxPopupMgr::VisibleRule);
1675   mgr->setRule(action(GEOMOp::OpSelectFace),     selectOnly + " and selectionmode='FACE'", QtxPopupMgr::ToggleRule);
1676   mgr->insert( action(GEOMOp::OpSelectShell),    selectonlyId, -1);                                  //Shell
1677   mgr->setRule(action(GEOMOp::OpSelectShell),    selectOnly, QtxPopupMgr::VisibleRule);
1678   mgr->setRule(action(GEOMOp::OpSelectShell),    selectOnly + " and selectionmode='SHELL'", QtxPopupMgr::ToggleRule);
1679   mgr->insert( action(GEOMOp::OpSelectSolid),    selectonlyId, -1);                                  //Solid
1680   mgr->setRule(action(GEOMOp::OpSelectSolid),    selectOnly, QtxPopupMgr::VisibleRule);
1681   mgr->setRule(action(GEOMOp::OpSelectSolid),    selectOnly + " and selectionmode='SOLID'", QtxPopupMgr::ToggleRule);
1682   mgr->insert( action(GEOMOp::OpSelectCompound), selectonlyId, -1);                                  //Compound
1683   mgr->setRule(action(GEOMOp::OpSelectCompound), selectOnly, QtxPopupMgr::VisibleRule);
1684   mgr->setRule(action(GEOMOp::OpSelectCompound), selectOnly + " and selectionmode='COMPOUND'", QtxPopupMgr::ToggleRule);
1685   mgr->insert( separator(), selectonlyId, -1);
1686   mgr->insert( action(GEOMOp::OpSelectAll),      selectonlyId, -1);                                  //Clear selection filter
1687   mgr->setRule(action(GEOMOp::OpSelectAll),      selectOnly, QtxPopupMgr::VisibleRule);
1688   mgr->setRule(action(GEOMOp::OpSelectAll),      selectOnly + " and selectionmode='ALL'", QtxPopupMgr::ToggleRule);
1689   mgr->insert( action(GEOMOp::OpShowOnly ), -1, -1 ); // display only
1690   mgr->setRule(action(GEOMOp::OpShowOnly ), rule.arg( types ).arg( "true" ), QtxPopupMgr::VisibleRule );
1691   mgr->insert( action(GEOMOp::OpShowOnlyChildren ), -1, -1 ); // display only children
1692   mgr->setRule(action(GEOMOp::OpShowOnlyChildren ), (canDisplay + "and ($type in {%1}) and client='ObjectBrowser' and hasChildren=true").arg( types ), QtxPopupMgr::VisibleRule );
1693
1694   QString aDimensionRule = "($component={'GEOM'}) and selcount=1 and isVisible and type='Shape' and %1";
1695
1696   mgr->insert( separator(), -1, -1 ); // -----------
1697   mgr->insert( action( GEOMOp::OpShowAllDimensions ), -1, -1 ); // show all dimensions
1698   mgr->setRule( action( GEOMOp::OpShowAllDimensions ), aDimensionRule.arg( "hasHiddenDimensions" ), QtxPopupMgr::VisibleRule );
1699   mgr->insert( action( GEOMOp::OpHideAllDimensions ), -1, -1 ); // hide all dimensions
1700   mgr->setRule( action( GEOMOp::OpHideAllDimensions ), aDimensionRule.arg( "hasVisibleDimensions" ), QtxPopupMgr::VisibleRule );
1701   mgr->insert( action( GEOMOp::OpShowAllAnnotations ), -1, -1 ); // show all annotations
1702   mgr->setRule( action( GEOMOp::OpShowAllAnnotations ), aDimensionRule.arg( "hasHiddenAnnotations" ), QtxPopupMgr::VisibleRule );
1703   mgr->insert( action( GEOMOp::OpHideAllAnnotations ), -1, -1 ); // hide all annotations
1704   mgr->setRule( action( GEOMOp::OpHideAllAnnotations ), aDimensionRule.arg( "hasVisibleAnnotations" ), QtxPopupMgr::VisibleRule );
1705
1706   mgr->insert( separator(), -1, -1 );     // -----------
1707   mgr->insert( action(  GEOMOp::OpUnpublishObject ), -1, -1 ); // Unpublish object
1708   mgr->setRule( action( GEOMOp::OpUnpublishObject ), QString("client='ObjectBrowser' and $type in {'Shape' 'Group' 'Field' 'FieldStep'} and selcount>0"), QtxPopupMgr::VisibleRule );
1709
1710   mgr->insert( action(  GEOMOp::OpPublishObject ), -1, -1 ); // Publish object
1711   mgr->setRule( action( GEOMOp::OpPublishObject ), QString("client='ObjectBrowser' and isComponent=true"), QtxPopupMgr::VisibleRule );
1712
1713   mgr->insert( action(  GEOMOp::OpReimport ), -1, -1 );  // delete
1714   mgr->setRule( action( GEOMOp::OpReimport ), QString("$imported in {'true'} and selcount>0"), QtxPopupMgr::VisibleRule );
1715
1716   mgr->insert( separator(), -1, -1 );     // -----------
1717   mgr->insert( action(  GEOMOp::OpCreateFolder ), -1, -1 ); // Create Folder
1718   mgr->setRule( action( GEOMOp::OpCreateFolder ), QString("client='ObjectBrowser' and $component={'GEOM'} and (isComponent=true or isFolder=true)"), QtxPopupMgr::VisibleRule );
1719
1720   mgr->insert( separator(), -1, -1 );     // -----------
1721   mgr->insert( action(  GEOMOp::OpSortChildren ), -1, -1 ); // Sort child items
1722   mgr->setRule( action( GEOMOp::OpSortChildren ), QString("client='ObjectBrowser' and $component={'GEOM'} and nbChildren>1"), QtxPopupMgr::VisibleRule );
1723
1724 #ifndef DISABLE_GRAPHICSVIEW
1725   mgr->insert( separator(), -1, -1 );     // -----------
1726   mgr->insert( action(  GEOMOp::OpShowDependencyTree ), -1, -1 ); // Show dependency tree
1727   mgr->setRule( action( GEOMOp::OpShowDependencyTree ), clientOCCorVTKorOB + " and selcount>0 and ($component={'GEOM'}) and type='Shape'", QtxPopupMgr::VisibleRule );
1728 #endif
1729
1730   mgr->insert( separator(), -1, -1 );     // -----------
1731   mgr->insert( action(  GEOMOp::OpReduceStudy ), -1, -1 ); // Reduce Study
1732   mgr->setRule( action( GEOMOp::OpReduceStudy ), clientOCCorVTKorOB + " and selcount>0 and ($component={'GEOM'}) and type='Shape'", QtxPopupMgr::VisibleRule );
1733
1734   mgr->hide( mgr->actionId( action( myEraseAll ) ) );
1735
1736   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1737   if (resMgr) {
1738     GEOM_AISShape::setTopLevelDisplayMode((GEOM_AISShape::TopLevelDispMode)resMgr->integerValue("Geometry", "toplevel_dm", 0));
1739     QColor c = resMgr->colorValue( "Geometry", "toplevel_color", QColor( 170, 85, 0 ) );
1740     GEOM_AISShape::setTopLevelColor(SalomeApp_Tools::color(c));
1741   }
1742
1743   // create plugin actions and menus
1744   addPluginActions();
1745 }
1746
1747 //=======================================================================
1748 // function : GeometryGUI::addPluginActions()
1749 // purpose  :
1750 //=======================================================================
1751 void GeometryGUI::addPluginActions()
1752 {
1753   // Resource manager
1754   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1755   if (!resMgr) return;
1756
1757   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
1758   if (!appStudy) return;
1759
1760   // Find names of a resource XML files ("AdvancedGEOM.xml" and others);
1761
1762   GEOMUtils::PluginInfo plugins = GEOMUtils::ReadPluginInfo();
1763
1764   int id = GEOMOp::OpLastOperationID; // TODO?
1765
1766   // loop on plugins
1767   GEOMUtils::PluginInfo::const_iterator it;
1768   for ( it = plugins.begin(); it != plugins.end(); ++it ) {
1769     // bind action lib and label to its ID for activateOperation() method proper work
1770     GEOMUtils::PluginData pdata = (*it);
1771     myPluginLibs[pdata.name.c_str()] = pdata.clientLib.c_str();
1772     std::list<GEOMUtils::ActionData> actions = (*it).actions;
1773     std::list<GEOMUtils::ActionData>::const_iterator ait;
1774     for ( ait = actions.begin(); ait != actions.end(); ++ait ) {
1775       GEOMUtils::ActionData adata = (*ait);
1776       // icon
1777       QPixmap icon;
1778       if ( !adata.icon.empty() )
1779         icon = resMgr->loadPixmap( pdata.name.c_str(), adata.icon.c_str() );
1780       // menu text (path)
1781       QStringList smenus = QString( adata.menuText.c_str() ).split( "/" );
1782       QString actionName = smenus.last();
1783       actionName = actionName.toUpper().prepend( "MEN_" );
1784       smenus.removeLast();
1785
1786       // path to action in toolbar
1787       QStringList stools = QString( adata.toolTip.c_str() ).split( "/" );
1788       QString actionTool = stools.last();
1789       actionTool = actionTool.toUpper().prepend( "TOP_" );
1790       stools.removeLast();
1791       
1792       QString actionStat = adata.statusText.c_str();
1793       actionStat = actionStat.toUpper().prepend( "STB_" );
1794
1795       createAction( id, // ~ adata.label
1796                     tr( actionTool.toLatin1().constData() ),
1797                     icon,
1798                     tr( actionName.toLatin1().constData() ),
1799                     tr( actionStat.toLatin1().constData() ),
1800                     QKeySequence( tr( adata.accel.c_str() ) ),
1801                     application()->desktop(),
1802                     false /*toggle*/,
1803                     this, SLOT( OnGUIEvent() ),
1804                     QString() /*shortcutAction*/ );
1805       
1806       int menuId = -1;
1807       foreach ( QString subMenu, smenus ) {
1808         QStringList subMenuList = subMenu.split( ":" );
1809         QString subMenuName = subMenuList[0].toUpper().prepend( "MEN_" );
1810         int subMenuGroup = subMenuList.size() > 1 ? subMenuList[1].toInt() : -1;
1811         menuId = createMenu( tr( subMenuName.toLatin1().constData() ), menuId, -1, subMenuGroup );
1812       }
1813       createMenu( id, menuId, -1 );
1814       
1815       if ( !stools.isEmpty() ) {
1816         QString subTool = stools[0];
1817         subTool = subTool.toUpper().prepend( "TOOL_" );
1818         int toolId = createTool( tr( subTool.toLatin1().constData() ) );
1819         createTool(id, toolId);
1820       }
1821
1822       // add action id to map
1823       PluginAction anAction( pdata.clientLib.c_str(), adata.label.c_str() );
1824       myPluginActions[id] = anAction;
1825       
1826       id++;
1827     }
1828   }
1829 }
1830
1831 //=======================================================================
1832 // function : GeometryGUI::activateModule()
1833 // purpose  : Called when GEOM module is activated
1834 //=======================================================================
1835 bool GeometryGUI::activateModule( SUIT_Study* study )
1836 {
1837   if ( CORBA::is_nil( myComponentGeom ) )
1838     return false;
1839
1840   bool res = SalomeApp_Module::activateModule( study );
1841
1842   if ( !res )
1843     return false;
1844   setMenuShown( true );
1845   setToolShown( true );
1846
1847   // import Python module that manages GEOM plugins (need to be here because SalomePyQt API uses active module)
1848   PyGILState_STATE gstate = PyGILState_Ensure();
1849   PyObject* pluginsmanager = PyImport_ImportModuleNoBlock((char*)"salome_pluginsmanager");
1850   if ( !pluginsmanager ) {
1851     PyErr_Print();
1852   }
1853   else {
1854     PyObject* result =
1855       PyObject_CallMethod(pluginsmanager, (char*)"initialize", (char*)"isss", 1, "geom",
1856                           tr("MEN_NEW_ENTITY").toUtf8().data(),
1857                           tr("GEOM_PLUGINS_OTHER").toUtf8().data());
1858     if ( !result )
1859       PyErr_Print();
1860     Py_XDECREF(result);
1861   }
1862   PyGILState_Release(gstate);
1863   // end of GEOM plugins loading
1864
1865   connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1866            this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ), Qt::UniqueConnection );
1867
1868   // Reset actions accelerator keys
1869   action(GEOMOp::OpDelete)->setEnabled( true ); // Delete: Key_Delete
1870
1871   GUIMap::Iterator it;
1872   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1873     it.value()->activate( application()->desktop() );
1874
1875   LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1876
1877   connect( sm, SIGNAL( currentSelectionChanged() ), this, SLOT( updateCreationInfo() ), Qt::UniqueConnection );
1878   connect( sm, SIGNAL( currentSelectionChanged() ), this, SLOT( onAutoBringToFront() ), Qt::UniqueConnection );
1879   connect( sm, SIGNAL( currentSelectionChanged() ), this, SLOT( updateFieldColorScale() ), Qt::UniqueConnection );
1880
1881   if ( !myCreationInfoWdg )
1882     myCreationInfoWdg = new GEOMGUI_CreationInfoWdg( getApp() );
1883   getApp()->insertDockWindow( myCreationInfoWdg->getWinID(), myCreationInfoWdg );
1884   getApp()->placeDockWindow( myCreationInfoWdg->getWinID(), Qt::LeftDockWidgetArea );
1885
1886   if ( !myTextTreeWdg ) {
1887     myTextTreeWdg = new GEOMGUI_TextTreeWdg( getApp() );
1888     new GEOMGUI_TextTreeSelector( myTextTreeWdg, GetAnnotationMgr(), getApp()->selectionMgr() );
1889   }
1890
1891   getApp()->insertDockWindow( myTextTreeWdg->getWinID(), myTextTreeWdg );
1892   getApp()->placeDockWindow( myTextTreeWdg->getWinID(), Qt::LeftDockWidgetArea );
1893
1894   //NPAL 19674
1895   SALOME_ListIO selected;
1896   sm->selectedObjects( selected );
1897   sm->clearSelected();
1898
1899   SUIT_ViewManager* vm;
1900   ViewManagerList OCCViewManagers, VTKViewManagers;
1901
1902   application()->viewManagers( OCCViewer_Viewer::Type(), OCCViewManagers );
1903   QListIterator<SUIT_ViewManager*> itOCC( OCCViewManagers );
1904   while ( itOCC.hasNext() && (vm = itOCC.next()) )
1905     onViewManagerAdded(vm);
1906
1907   application()->viewManagers( SVTK_Viewer::Type(), VTKViewManagers );
1908   QListIterator<SUIT_ViewManager*> itVTK( VTKViewManagers );
1909   while ( itVTK.hasNext() && (vm = itVTK.next()) )
1910     onViewManagerAdded(vm);
1911
1912   sm->setSelectedObjects( selected, true );   //NPAL 19674
1913
1914   QMenu* viewMenu = menuMgr()->findMenu( STD_Application::MenuViewId );
1915   if ( viewMenu )
1916     connect( viewMenu, SIGNAL( aboutToShow() ), this, SLOT( onViewAboutToShow() ), Qt::UniqueConnection );
1917
1918   // 0020836 (Basic vectors and origin)
1919   SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
1920   if ( aResourceMgr->booleanValue( "Geometry", "auto_create_base_objects", false ) ) {
1921     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
1922     if ( appStudy ) {
1923       _PTR(Study) studyDS = appStudy->studyDS();
1924       if ( studyDS ) {
1925         _PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
1926         if ( !aSComponent ) // create objects automatically only if there is no GEOM component
1927           createOriginAndBaseVectors();
1928       }
1929     }
1930   }
1931
1932   Py_XDECREF(pluginsmanager);
1933   return true;
1934 }
1935
1936 //=======================================================================
1937 // function : GeometryGUI::deactivateModule()
1938 // purpose  : Called when GEOM module is deactivated
1939 //=======================================================================
1940 bool GeometryGUI::deactivateModule( SUIT_Study* study )
1941 {
1942   QMenu* viewMenu = menuMgr()->findMenu( STD_Application::MenuViewId );
1943   if ( viewMenu )
1944     disconnect( viewMenu, SIGNAL( aboutToShow() ), this, SLOT( onViewAboutToShow() ) );
1945
1946   setMenuShown( false );
1947   setToolShown( false );
1948
1949   disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1950              this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1951
1952   LightApp_SelectionMgr* selMrg = getApp()->selectionMgr();
1953
1954   disconnect( selMrg, SIGNAL( currentSelectionChanged() ), this, SLOT( updateCreationInfo() ));
1955   //disconnect( selMrg, SIGNAL( currentSelectionChanged() ), this, SLOT( updateFieldColorScale() ));
1956   if ( myCreationInfoWdg ) {
1957     getApp()->removeDockWindow( myCreationInfoWdg->getWinID() );
1958     myCreationInfoWdg = 0;
1959   }
1960   if ( myTextTreeWdg ) {
1961     getApp()->removeDockWindow( myTextTreeWdg->getWinID() );
1962     disconnect( application(), 0, myTextTreeWdg, 0 );
1963     myTextTreeWdg = 0;
1964   }
1965
1966   EmitSignalCloseAllDialogs();
1967
1968   GUIMap::Iterator it;
1969   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1970     it.value()->deactivate();
1971
1972   // Unset actions accelerator keys
1973   action(GEOMOp::OpDelete)->setEnabled( false ); // Delete: Key_Delete
1974
1975   qDeleteAll(myOCCSelectors);
1976   myOCCSelectors.clear();
1977   selMrg->setEnabled( true, OCCViewer_Viewer::Type() );
1978
1979   qDeleteAll(myVTKSelectors);
1980   myVTKSelectors.clear();
1981   selMrg->setEnabled( true, SVTK_Viewer::Type() );
1982
1983   return SalomeApp_Module::deactivateModule( study );
1984 }
1985
1986 //=======================================================================
1987 // function : onWindowActivated()
1988 // purpose  : update menu items' status - disable non-OCC-viewer-compatible actions
1989 //=======================================================================
1990 void GeometryGUI::onWindowActivated( SUIT_ViewWindow* win )
1991 {
1992   if ( !win )
1993     return;
1994
1995   const bool ViewOCC = ( win->getViewManager() ? win->getViewManager()->getType() == OCCViewer_Viewer::Type() : false );
1996   //const bool ViewVTK = ( win->getViewManager() ? win->getViewManager()->getType() == SVTK_Viewer::Type() : false );
1997
1998   // disable non-OCC viewframe menu commands
1999 //  action( GEOMOp::Op2dSketcher )->setEnabled( ViewOCC ); // SKETCHER
2000   action( GEOMOp::OpSuppressFaces )->setEnabled( ViewOCC ); // SuppressFace
2001   action( GEOMOp::OpSuppressHoles )->setEnabled( ViewOCC ); // SuppressHole
2002   action( GEOMOp::OpCloseContour )->setEnabled( ViewOCC ); // CloseContour
2003   action( GEOMOp::OpRemoveIntWires )->setEnabled( ViewOCC ); // RemoveInternalWires
2004   action( GEOMOp::OpAddPointOnEdge )->setEnabled( ViewOCC ); // AddPointOnEdge
2005 //  action( GEOMOp::OpFreeBoundaries )->setEnabled( ViewOCC ); // Free boundaries
2006
2007   action( GEOMOp::OpGroupCreate )->setEnabled( ViewOCC ); // Create Group
2008   action( GEOMOp::OpGroupEdit )->setEnabled( ViewOCC ); // Edit Group
2009   action( GEOMOp::OpCreateField )->setEnabled( ViewOCC ); // Create Field
2010   action( GEOMOp::OpEditField )->setEnabled( ViewOCC ); // Edit Field
2011
2012   action( GEOMOp::OpMultiTransform )->setEnabled( ViewOCC ); // MENU BLOCKS - MULTI-TRANSFORMATION
2013 }
2014
2015 void GeometryGUI::windows( QMap<int, int>& mappa ) const
2016 {
2017   mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
2018   mappa.insert( SalomeApp_Application::WT_NoteBook, Qt::LeftDockWidgetArea );
2019 #ifndef DISABLE_PYCONSOLE
2020   mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
2021 #endif
2022   if ( myCreationInfoWdg )
2023     mappa.insert( myCreationInfoWdg->getWinID(), Qt::LeftDockWidgetArea );
2024   if ( myTextTreeWdg )
2025     mappa.insert( myTextTreeWdg->getWinID(), Qt::LeftDockWidgetArea );
2026 }
2027
2028 void GeometryGUI::viewManagers( QStringList& lst ) const
2029 {
2030   lst.append( OCCViewer_Viewer::Type() );
2031 }
2032
2033 void GeometryGUI::onViewManagerAdded( SUIT_ViewManager* vm )
2034 {
2035   if ( vm && vm->getType() == OCCViewer_Viewer::Type() )
2036   {
2037     qDebug( "connect" );
2038     connect( vm, SIGNAL( keyPress  ( SUIT_ViewWindow*, QKeyEvent* ) ),
2039              this, SLOT( OnKeyPress( SUIT_ViewWindow*, QKeyEvent* ) ) );
2040     connect( vm, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
2041              this, SLOT( OnMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
2042     connect( vm, SIGNAL( mouseMove ( SUIT_ViewWindow*, QMouseEvent* ) ),
2043              this, SLOT( OnMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
2044     connect( vm, SIGNAL( mouseRelease ( SUIT_ViewWindow*, QMouseEvent* ) ),
2045              this, SLOT( OnMouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ) );
2046
2047     LightApp_SelectionMgr* sm = getApp()->selectionMgr();
2048     myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
2049
2050     // disable OCC selectors
2051     getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
2052     QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
2053     while ( itOCCSel.hasNext() )
2054       if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
2055         sr->setEnabled(true);
2056   }
2057   else if ( vm->getType() == SVTK_Viewer::Type() )
2058   {
2059     LightApp_SelectionMgr* sm = getApp()->selectionMgr();
2060     myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
2061
2062     // disable VTK selectors
2063     getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
2064     QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
2065     while ( itVTKSel.hasNext() )
2066       if ( LightApp_VTKSelector* sr = itVTKSel.next() )
2067         sr->setEnabled(true);
2068   }
2069 }
2070
2071 void GeometryGUI::onViewManagerRemoved( SUIT_ViewManager* vm )
2072 {
2073   SUIT_ViewModel* viewer = vm->getViewModel();
2074   if ( vm->getType() == OCCViewer_Viewer::Type() )
2075   {
2076     QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
2077     while ( itOCCSel.hasNext() )
2078       if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
2079         if ( sr->viewer() == viewer )
2080         {
2081           /*delete*/ myOCCSelectors.takeAt( myOCCSelectors.indexOf( sr ) );
2082           break;
2083         }
2084   }
2085   if ( vm->getType() == SVTK_Viewer::Type() )
2086   {
2087     QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
2088     while ( itVTKSel.hasNext() )
2089       if ( LightApp_VTKSelector* sr = itVTKSel.next() )
2090         if ( sr->viewer() == viewer )
2091         {
2092           /*delete*/ myVTKSelectors.takeAt( myVTKSelectors.indexOf( sr ) );
2093           break;
2094         }
2095   }
2096   SOCC_Viewer* aSOCCView = dynamic_cast<SOCC_Viewer*>(viewer);
2097   if ( aSOCCView ) {
2098     GetAnnotationMgr()->RemoveView( aSOCCView );
2099   }
2100 }
2101
2102 //================================================================================
2103 /*!
2104  * \brief Slot called when selection changed. Shows creation info of a selected object
2105  */
2106 //================================================================================
2107
2108 void GeometryGUI::updateCreationInfo()
2109 {
2110   if ( myCreationInfoWdg )
2111     myCreationInfoWdg->clear();
2112
2113   // Code below is commented to have myCreationInfoWdg filled as soon as it is shown again
2114   // if ( !myCreationInfoWdg->isVisible() )
2115   //   return;
2116
2117   // look for a sole selected GEOM_Object
2118   GEOM::GEOM_BaseObject_var geomObj;
2119
2120   SALOME_ListIO selected;
2121   getApp()->selectionMgr()->selectedObjects( selected );
2122
2123   _PTR(Study) study = dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() )->studyDS();
2124   SALOME_ListIteratorOfListIO selIt( selected );
2125   for ( ; selIt.More(); selIt.Next() )
2126   {
2127     Handle(SALOME_InteractiveObject) io = selIt.Value();
2128     if ( !io->hasEntry() ) continue;
2129     _PTR(SObject) sobj = study->FindObjectID( io->getEntry() );
2130     if ( !sobj ) continue;
2131     CORBA::Object_var          obj = GeometryGUI::ClientSObjectToObject( sobj );
2132     GEOM::GEOM_BaseObject_var gobj = GEOM::GEOM_BaseObject::_narrow( obj );
2133     if ( !gobj->_is_nil() )
2134     {
2135       if ( !geomObj->_is_nil() )
2136         return; // several GEOM objects selected
2137       geomObj = gobj;
2138     }
2139   }
2140   if ( geomObj->_is_nil() ) return;
2141
2142   // pass creation info of geomObj to myCreationInfoWdg
2143
2144   if ( myCreationInfoWdg ) {
2145
2146     GEOM::CreationInformationSeq_var info;
2147     try {
2148       OCC_CATCH_SIGNALS;
2149       info = geomObj->GetCreationInformation();
2150     }
2151     catch (...) {
2152     }
2153     myCreationInfoWdg->setInfo( info );
2154   }
2155 }
2156
2157 void GeometryGUI::onAutoBringToFront()
2158 {
2159   bool isAutoBringToFront = SUIT_Session::session()->resourceMgr()->booleanValue( "Geometry", "auto_bring_to_front", "false" );
2160   if( !isAutoBringToFront )
2161     return;
2162   
2163   SUIT_ViewWindow* SUIT_window = application()->desktop()->activeWindow();
2164   if ( !SUIT_window || SUIT_window->getViewManager()->getType() != OCCViewer_Viewer::Type() )
2165         return;
2166
2167   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( getApp()->activeStudy() );
2168   if (!appStudy) return;
2169
2170   GEOM_Displayer displayer( appStudy );
2171   
2172   SALOME_View* window = displayer.GetActiveView();
2173   if ( !window ) return;
2174   
2175   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
2176   
2177   SALOME_ListIO selected;
2178   getApp()->selectionMgr()->selectedObjects( selected );
2179   if (!myTopLevelIOList.IsEmpty())
2180   {
2181     for( SALOME_ListIteratorOfListIO It( myTopLevelIOList ); It.More(); It.Next() )
2182     {
2183       Handle( SALOME_InteractiveObject ) io = It.Value();
2184       bool isSelected = false;
2185       for( SALOME_ListIteratorOfListIO It_sel( selected ); It_sel.More(); It_sel.Next() )
2186       {
2187         Handle( SALOME_InteractiveObject ) sel_io = It_sel.Value();
2188         if( io->isSame( sel_io ) )
2189           isSelected = true;
2190       }
2191       if (!isSelected && appStudy->findObjectByEntry(io->getEntry()))
2192       {
2193         appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::TopLevel ), false );
2194         if ( window->isVisible( io ) ) displayer.Redisplay( io, false );     
2195       }
2196     }
2197   }
2198   
2199   myTopLevelIOList.Assign(selected);
2200   for( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() )
2201   {
2202     Handle( SALOME_InteractiveObject ) io = It.Value();
2203     appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::TopLevel ), true );
2204     if ( window->isVisible( io ) ) displayer.Redisplay( io, false );     
2205   }
2206     
2207   displayer.UpdateViewer();
2208   GeometryGUI::Modified();
2209 }
2210
2211 void GeometryGUI::updateFieldColorScale()
2212 {
2213   if( SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) )
2214   {
2215     GEOM_Displayer( aStudy ).UpdateColorScale();
2216   }
2217 }
2218
2219 QString GeometryGUI::engineIOR() const
2220 {
2221   if ( !CORBA::is_nil( GetGeomGen() ) )
2222     return QString( getApp()->orb()->object_to_string( GetGeomGen() ) );
2223   return "";
2224 }
2225
2226 Handle(TColStd_HArray1OfByte) GeometryGUI::getTexture
2227       (SalomeApp_Study* theStudy, int theId, int& theWidth, int& theHeight)
2228 {
2229   theWidth = theHeight = 0;
2230
2231   Handle(TColStd_HArray1OfByte) aTexture;
2232
2233   if (theStudy) {
2234     TextureMap aTextureMap = myTextureMap[ theStudy->studyDS()->StudyId() ];
2235     aTexture = aTextureMap[ theId ];
2236     if ( aTexture.IsNull() ) {
2237       GEOM::GEOM_IInsertOperations_var aInsOp = GeometryGUI::GetGeomGen()->GetIInsertOperations( theStudy->studyDS()->StudyId() );
2238       if ( !aInsOp->_is_nil() ) {
2239         CORBA::Long aWidth, aHeight;
2240         SALOMEDS::TMPFile_var aStream = aInsOp->GetTexture( theId, aWidth, aHeight );
2241         if ( aWidth > 0 && aHeight > 0 && aStream->length() > 0 ) {
2242           theWidth  = aWidth;
2243           theHeight = aHeight;
2244
2245           aTexture  = new TColStd_HArray1OfByte (1, aStream->length());
2246
2247           for ( CORBA::ULong i = 0; i < aStream->length(); i++)
2248             aTexture->SetValue( i+1, (Standard_Byte)aStream[i] );
2249           aTextureMap[ theId ] = aTexture;
2250         }
2251       }
2252     }
2253   }
2254   return aTexture;
2255 }
2256
2257 LightApp_Selection* GeometryGUI::createSelection() const
2258 {
2259   return new GEOMGUI_Selection();
2260 }
2261
2262 void GeometryGUI::contextMenuPopup( const QString& client, QMenu* menu, QString& title )
2263 {
2264   SalomeApp_Module::contextMenuPopup( client, menu, title );
2265   SALOME_ListIO lst;
2266   getApp()->selectionMgr()->selectedObjects( lst );
2267
2268   //Add submenu for predefined materials
2269   bool isPredefMat = SUIT_Session::session()->resourceMgr()->booleanValue( "Geometry", "predef_materials" );
2270   if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() > 0 ) {
2271     QtxPopupMgr* mgr = popupMgr();
2272     //get parrent for submenu
2273     QAction* act = mgr->action( mgr->actionId( action(  GEOMOp::OpMaterialProperties ) ) );
2274     //Clear old  menu
2275     QMenu* oldMenu = act->menu() ;
2276     if( oldMenu ) {
2277       delete oldMenu;
2278     }
2279     if( isPredefMat ){
2280       QMenu* matMenu = new QMenu();
2281       QSignalMapper* signalMapper = new QSignalMapper( matMenu );
2282
2283       //Get current material model for the object
2284       QVariant v;
2285       LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( getApp() );
2286       if ( anApp && anApp->activeViewManager() ) {
2287         LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( anApp->activeStudy() );
2288         if( aStudy ) {
2289           v = aStudy->getObjectProperty( anApp->activeViewManager()->getGlobalId(), lst.Last()->getEntry(), GEOM::propertyName( GEOM::Material ), QVariant() );
2290         }
2291       }
2292       QString curModel = "";
2293       if ( v.canConvert<QString>() ) curModel = v.toString();
2294       // get list of all predefined materials
2295       QStringList materials = Material_ResourceMgr::resourceMgr()->materials();
2296       bool found = false;
2297       foreach ( QString material, materials )
2298       {
2299         QAction* menAct = matMenu->addAction( material );
2300         connect(menAct, SIGNAL( toggled( bool ) ), signalMapper, SLOT( map() ) );
2301         signalMapper->setMapping( menAct, material );
2302         menAct->setCheckable( true );
2303         // Set checked if this material is current
2304         Material_Model aModel;
2305         aModel.fromResources( material );
2306         if ( !found && aModel.toProperties() == curModel ) {
2307           menAct->setChecked( true );
2308           found = true;
2309         }
2310       }
2311       matMenu->insertAction( matMenu->addSeparator(), action(  GEOMOp::OpPredefMaterCustom ) );
2312       matMenu->insertSeparator( action(  GEOMOp::OpPredefMaterCustom ) );
2313       connect( signalMapper, SIGNAL( mapped( const QString & ) ),
2314                  this, SLOT( OnSetMaterial( const QString & ) ) );
2315       act->setMenu( matMenu );
2316     }
2317   }
2318   //Set name
2319   if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
2320     Handle(SALOME_InteractiveObject) io = lst.First();
2321     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
2322     _PTR(Study) study = appStudy->studyDS();
2323     _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
2324     if ( obj ) {
2325       QString aName = QString( obj->GetName().c_str() );
2326       aName.remove( QRegExp("\\s+$") );
2327       title = aName;
2328     }
2329   }
2330 }
2331
2332 void GeometryGUI::OnSetMaterial(const QString& theName)
2333 {
2334   OnGUIEvent( GEOMOp::OpPredefMaterial, QVariant( theName ) );
2335 }
2336
2337
2338 void GeometryGUI::createPreferences()
2339 {
2340   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2341
2342   int tabId = addPreference( tr( "PREF_TAB_SETTINGS" ) );
2343
2344   int genGroup = addPreference( tr( "PREF_GROUP_GENERAL" ), tabId );
2345   setPreferenceProperty( genGroup, "columns", 2 );
2346
2347   int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), genGroup,
2348                                 LightApp_Preferences::Selector,
2349                                 "Geometry", "display_mode" );
2350
2351   addPreference( tr( "PREF_SHADING_COLOR" ), genGroup,
2352                  LightApp_Preferences::Color, "Geometry", "shading_color" );
2353
2354   addPreference( tr( "PREF_EDGES_IN_SHADING" ), genGroup,
2355                  LightApp_Preferences::Color, "Geometry", "edges_in_shading_color" );
2356
2357   addPreference( tr( "PREF_WIREFRAME_COLOR" ), genGroup,
2358                  LightApp_Preferences::Color, "Geometry", "wireframe_color" );
2359
2360   addPreference( tr( "PREF_FREE_BOUND_COLOR" ), genGroup,
2361                  LightApp_Preferences::Color, "Geometry", "free_bound_color" );
2362
2363   addPreference( tr( "PREF_LINE_COLOR"), genGroup,
2364                  LightApp_Preferences::Color, "Geometry", "line_color" );
2365
2366   addPreference( tr( "PREF_POINT_COLOR"), genGroup,
2367                  LightApp_Preferences::Color, "Geometry", "point_color" );
2368
2369   addPreference( tr( "PREF_ISOS_COLOR" ), genGroup,
2370                  LightApp_Preferences::Color, "Geometry", "isos_color" );
2371
2372   addPreference( tr( "PREF_LABEL_COLOR" ), genGroup,
2373                  LightApp_Preferences::Color, "Geometry", "label_color" );
2374
2375   addPreference( "", genGroup, LightApp_Preferences::Space );
2376
2377   addPreference( tr( "PREF_TOPLEVEL_COLOR" ), genGroup,
2378                  LightApp_Preferences::Color, "Geometry", "toplevel_color" );
2379
2380   int top_lev_dm = addPreference( tr( "PREF_TOPLEVEL_DM" ), genGroup,
2381                       LightApp_Preferences::Selector, "Geometry", "toplevel_dm" );
2382
2383   int transparency = addPreference( tr( "PREF_TRANSPARENCY" ), genGroup,
2384                                     LightApp_Preferences::IntSpin, "Geometry", "transparency" );
2385
2386   int defl = addPreference( tr( "PREF_DEFLECTION" ), genGroup,
2387                             LightApp_Preferences::DblSpin, "Geometry", "deflection_coeff" );
2388
2389   addPreference( tr( "PREF_PREDEF_MATERIALS" ), genGroup,
2390                  LightApp_Preferences::Bool, "Geometry", "predef_materials" );
2391
2392   int material = addPreference( tr( "PREF_MATERIAL" ), genGroup,
2393                                 LightApp_Preferences::Selector,
2394                                 "Geometry", "material" );
2395
2396   addPreference( tr( "PREF_EDITGROUP_COLOR" ), genGroup,
2397                  LightApp_Preferences::Color, "Geometry", "editgroup_color" );
2398
2399   const int nb = 4;
2400   int wd[nb];
2401   int iter=0;
2402
2403   wd[iter++] = addPreference( tr( "PREF_EDGE_WIDTH" ), genGroup,
2404                               LightApp_Preferences::IntSpin, "Geometry", "edge_width" );
2405
2406   wd[iter++] = addPreference( tr( "PREF_ISOLINES_WIDTH" ), genGroup,
2407                               LightApp_Preferences::IntSpin, "Geometry", "isolines_width" );
2408
2409   wd[iter++] = addPreference( tr( "PREF_PREVIEW_EDGE_WIDTH" ), genGroup,
2410                                      LightApp_Preferences::IntSpin, "Geometry", "preview_edge_width" );
2411
2412   wd[iter++] = addPreference( tr( "PREF_MEASURES_LINE_WIDTH" ), genGroup,
2413                               LightApp_Preferences::IntSpin, "Geometry", "measures_line_width" );
2414
2415   for (int i = 0; i < nb; i++) {
2416     setPreferenceProperty( wd[i], "min", 1 );
2417     setPreferenceProperty( wd[i], "max", 5 );
2418   }
2419
2420   int step = addPreference( tr( "PREF_STEP_VALUE" ), genGroup,
2421                             LightApp_Preferences::IntSpin, "Geometry", "SettingsGeomStep" );
2422
2423   addPreference( tr( "PREF_AUTO_BRING_TO_FRONT" ), genGroup,
2424                  LightApp_Preferences::Bool, "Geometry", "auto_bring_to_front" );
2425
2426   // --------------------------------------------------------------------------
2427   // Dimensions (Measurements) preferences
2428   // --------------------------------------------------------------------------
2429
2430   int aDimGroupId = addPreference( tr( "PREF_DIMENSIONS" ), tabId );
2431   setPreferenceProperty( aDimGroupId, "columns", 2 );
2432
2433   addPreference( tr( "PREF_DIMENSIONS_COLOR" ), aDimGroupId,
2434                  LightApp_Preferences::Color, "Geometry", "dimensions_color" );
2435
2436   int aDimLineWidthId = addPreference( tr( "PREF_DIMENSIONS_LINE_WIDTH" ), aDimGroupId, 
2437                                        LightApp_Preferences::IntSpin, "Geometry", "dimensions_line_width" );
2438
2439   setPreferenceProperty( aDimLineWidthId, "min", 1 );
2440   setPreferenceProperty( aDimLineWidthId, "max", 5 );
2441
2442   int aDimFontId = addPreference( tr( "PREF_DIMENSIONS_FONT" ), aDimGroupId, LightApp_Preferences::Font, "Geometry", "dimensions_font" );
2443
2444   int f = QtxFontEdit::Family | QtxFontEdit::Size;
2445   setPreferenceProperty( aDimFontId, "features", f );
2446   setPreferenceProperty( aDimFontId, "mode", QtxFontEdit::Custom );
2447
2448   Handle(Font_FontMgr) fmgr = Font_FontMgr::GetInstance();
2449   QString aFontFile = "";
2450   resMgr->value("resources", "GEOM", aFontFile);
2451   aFontFile = aFontFile + QDir::separator() + "Y14.5M-2009.ttf";
2452   // add enginier font into combobox
2453   /*int fontID =*/ QFontDatabase::addApplicationFont( aFontFile );
2454   Handle(Font_SystemFont) sf = new Font_SystemFont( 
2455     new TCollection_HAsciiString("Y14.5M-2009"), 
2456     Font_FA_Regular, 
2457     new TCollection_HAsciiString(aFontFile.toLatin1().data()) );
2458   // register font in OCC font manager
2459   fmgr->RegisterFont( sf, Standard_False );
2460
2461   // get list of supported fonts by OCC
2462   QStringList anOCCFonts;
2463   TColStd_SequenceOfHAsciiString theFontsNames;
2464   fmgr->GetAvailableFontsNames( theFontsNames );
2465   for(Standard_Integer i=1; i<=theFontsNames.Length(); i++) {
2466     Handle(TCollection_HAsciiString) str = theFontsNames(i);
2467     anOCCFonts << str->ToCString();
2468   }
2469   anOCCFonts.removeDuplicates();
2470   // set the supported fonts into combobox to use its only
2471   setPreferenceProperty( aDimFontId, "fonts", anOCCFonts );
2472
2473   int aDimArrLengthId = addPreference( tr( "PREF_DIMENSIONS_ARROW_LENGTH" ), aDimGroupId,
2474                                        LightApp_Preferences::DblSpin, "Geometry", "dimensions_arrow_length" );
2475
2476   setPreferenceProperty( aDimArrLengthId, "min", 1e-9 );
2477   setPreferenceProperty( aDimArrLengthId, "max", 1e+9 );
2478   setPreferenceProperty( aDimArrLengthId, "precision", 9 );
2479
2480   int aLengthUnitsId = addPreference( tr( "PREF_DIMENSIONS_LENGTH_UNITS" ), aDimGroupId,
2481                                       LightApp_Preferences::Selector, "Geometry", "dimensions_length_units" );
2482
2483   int anAngUnitsId = addPreference( tr( "PREF_DIMENSIONS_ANGLE_UNITS" ), aDimGroupId,
2484                                    LightApp_Preferences::Selector, "Geometry", "dimensions_angle_units" );
2485
2486   QStringList aListOfLengthUnits;
2487   aListOfLengthUnits << "m";
2488   aListOfLengthUnits << "cm";
2489   aListOfLengthUnits << "mm";
2490   aListOfLengthUnits << "in.";
2491   aListOfLengthUnits << "ft.";
2492
2493   QStringList aListOfAngUnits;
2494   aListOfAngUnits << "rad";
2495   aListOfAngUnits << "deg";
2496
2497   setPreferenceProperty( aLengthUnitsId, "strings", aListOfLengthUnits );
2498   setPreferenceProperty( anAngUnitsId,   "strings", aListOfAngUnits );
2499
2500   addPreference( tr( "PREF_DIMENSIONS_SHOW_UNITS" ), aDimGroupId,
2501                  LightApp_Preferences::Bool, "Geometry", "dimensions_show_units" );
2502
2503   int aDimDefFlyout = addPreference( tr( "PREF_DIMENSIONS_DEFAULT_FLYOUT" ), aDimGroupId,
2504                                      LightApp_Preferences::DblSpin, "Geometry", "dimensions_default_flyout" );
2505
2506   setPreferenceProperty( aDimDefFlyout, "min", 1e-9 );
2507   setPreferenceProperty( aDimDefFlyout, "max", 1e+9 );
2508   setPreferenceProperty( aDimDefFlyout, "precision", 9 );
2509
2510   addPreference( tr( "PREF_DIMENSIONS_USE_TEXT3D" ), aDimGroupId,
2511                  LightApp_Preferences::Bool, "Geometry", "dimensions_use_text3d" );
2512
2513   // --------------------------------------------------------------------------
2514   // Shape annotation preferences
2515   // --------------------------------------------------------------------------
2516
2517   const int aShapeAnnGroupId = addPreference( tr( "PREF_SHAPE_ANNOTATIONS" ), tabId );
2518   setPreferenceProperty( aShapeAnnGroupId, "columns", 2 );
2519
2520   addPreference( tr( "PREF_SHAPE_ANNOTATIONS_FONT_COLOR" ), aShapeAnnGroupId, LightApp_Preferences::Color, "Geometry", "shape_annotation_font_color" );
2521   addPreference( tr( "PREF_SHAPE_ANNOTATIONS_LINE_COLOR" ), aShapeAnnGroupId, LightApp_Preferences::Color, "Geometry", "shape_annotation_line_color" );
2522   const int aShapeAnnFont = 
2523     addPreference( tr( "PREF_SHAPE_ANNOTATIONS_FONT" ), aShapeAnnGroupId, LightApp_Preferences::Font, "Geometry", "shape_annotation_font" );
2524
2525   int aShapeAnnFontFeatures = QtxFontEdit::Family | QtxFontEdit::Size | QtxFontEdit::Bold | QtxFontEdit::Italic;
2526   setPreferenceProperty( aShapeAnnFont, "features", aShapeAnnFontFeatures );
2527   setPreferenceProperty( aShapeAnnFont, "mode", QtxFontEdit::Custom );
2528   setPreferenceProperty( aShapeAnnFont, "fonts", anOCCFonts );
2529
2530   const int aShapeAnnLineWidth = 
2531     addPreference( tr( "PREF_SHAPE_ANNOTATIONS_LINE_WIDTH" ), aShapeAnnGroupId, LightApp_Preferences::IntSpin, "Geometry", "shape_annotation_line_width" );
2532
2533   setPreferenceProperty( aShapeAnnLineWidth, "min", 1 );
2534   setPreferenceProperty( aShapeAnnLineWidth, "max", 5 );
2535
2536   addPreference( tr( "PREF_SHAPE_ANNOTATIONS_AUTOHIDE" ), aShapeAnnGroupId, LightApp_Preferences::Bool, "Geometry", "shape_annotation_autohide" );
2537
2538   const int aShapeAnnLineStyle =
2539     addPreference( tr( "PREF_SHAPE_ANNOTATIONS_LINE_STYLE" ), aShapeAnnGroupId, LightApp_Preferences::Selector, "Geometry", "shape_annotation_line_style" );
2540
2541   QStringList aLineStyleList;
2542   aLineStyleList.append( tr("PREF_SHAPE_ANNOTATIONS_LINESTYLE_SOLID") );
2543   aLineStyleList.append( tr("PREF_SHAPE_ANNOTATIONS_LINESTYLE_DASH") );
2544   aLineStyleList.append( tr("PREF_SHAPE_ANNOTATIONS_LINESTYLE_DOT") );
2545   aLineStyleList.append( tr("PREF_SHAPE_ANNOTATIONS_LINESTYLE_DOTDASH") );
2546
2547   QList<QVariant> aLineStyleIds;
2548   aLineStyleIds.append(0);
2549   aLineStyleIds.append(1);
2550   aLineStyleIds.append(2);
2551   aLineStyleIds.append(3);
2552
2553   setPreferenceProperty( aShapeAnnLineStyle, "strings", aLineStyleList );
2554   setPreferenceProperty( aShapeAnnLineStyle, "indexes", aLineStyleIds );
2555
2556   // --------------------------------------------------------------------------
2557   // Isoline drawing preferences
2558   // --------------------------------------------------------------------------
2559
2560   int isoGroup = addPreference( tr( "PREF_ISOS" ), tabId );
2561   setPreferenceProperty( isoGroup, "columns", 2 );
2562   int isoU = addPreference( tr( "PREF_ISOS_U" ), isoGroup,
2563                             LightApp_Preferences::IntSpin, "Geometry", "iso_number_u" );
2564   setPreferenceProperty( isoU, "min", 0 );
2565   setPreferenceProperty( isoU, "max", 100000 );
2566   int isoV = addPreference( tr( "PREF_ISOS_V" ), isoGroup,
2567                             LightApp_Preferences::IntSpin, "Geometry", "iso_number_v" );
2568   setPreferenceProperty( isoV, "min", 0 );
2569   setPreferenceProperty( isoV, "max", 100000 );
2570
2571   // Quantities with individual precision settings
2572   int precGroup = addPreference( tr( "GEOM_PREF_GROUP_PRECISION" ), tabId );
2573   setPreferenceProperty( precGroup, "columns", 2 );
2574
2575   const int nbQuantities = 8;
2576   int prec[nbQuantities], ii = 0;
2577   prec[ii++] = addPreference( tr( "GEOM_PREF_length_precision" ), precGroup,
2578                               LightApp_Preferences::IntSpin, "Geometry", "length_precision" );
2579   prec[ii++] = addPreference( tr( "GEOM_PREF_angle_precision" ), precGroup,
2580                               LightApp_Preferences::IntSpin, "Geometry", "angle_precision" );
2581   prec[ii++] = addPreference( tr( "GEOM_PREF_len_tol_precision" ), precGroup,
2582                               LightApp_Preferences::IntSpin, "Geometry", "len_tol_precision" );
2583   prec[ii++] = addPreference( tr( "GEOM_PREF_ang_tol_precision" ), precGroup,
2584                               LightApp_Preferences::IntSpin, "Geometry", "ang_tol_precision" );
2585   prec[ii++] = addPreference( tr( "GEOM_PREF_weight_precision" ), precGroup,
2586                               LightApp_Preferences::IntSpin, "Geometry", "weight_precision" );
2587   prec[ii++] = addPreference( tr( "GEOM_PREF_density_precision" ), precGroup,
2588                               LightApp_Preferences::IntSpin, "Geometry", "density_precision" );
2589   prec[ii++] = addPreference( tr( "GEOM_PREF_parametric_precision" ), precGroup,
2590                               LightApp_Preferences::IntSpin, "Geometry", "parametric_precision" );
2591   prec[ii  ] = addPreference( tr( "GEOM_PREF_param_tol_precision" ), precGroup,
2592                               LightApp_Preferences::IntSpin, "Geometry", "param_tol_precision" );
2593
2594   // Set property for precision value for spinboxes
2595   for ( ii = 0; ii < nbQuantities; ii++ ){
2596     setPreferenceProperty( prec[ii], "min", -14 );
2597     setPreferenceProperty( prec[ii], "max", 14 );
2598     setPreferenceProperty( prec[ii], "precision", 2 );
2599   }
2600
2601   int VertexGroup = addPreference( tr( "PREF_GROUP_VERTEX" ), tabId );
2602   setPreferenceProperty( VertexGroup, "columns", 2 );
2603
2604   int typeOfMarker = addPreference( tr( "PREF_TYPE_OF_MARKER" ), VertexGroup,
2605                                     LightApp_Preferences::Selector, "Geometry", "type_of_marker" );
2606
2607   int markerScale = addPreference( tr( "PREF_MARKER_SCALE" ), VertexGroup,
2608                                    LightApp_Preferences::Selector, "Geometry", "marker_scale" );
2609
2610   // Set property for default display mode
2611   QStringList aModesList;
2612   aModesList.append( tr("MEN_WIREFRAME") );
2613   aModesList.append( tr("MEN_SHADING") );
2614   aModesList.append( tr("MEN_SHADING_WITH_EDGES") );
2615   aModesList.append( tr("MEN_TEXTURE") );
2616
2617   QList<QVariant> anIndexesList;
2618   anIndexesList.append(0);
2619   anIndexesList.append(1);
2620   anIndexesList.append(2);
2621   anIndexesList.append(3);
2622
2623   setPreferenceProperty( dispmode, "strings", aModesList );
2624   setPreferenceProperty( dispmode, "indexes", anIndexesList );
2625
2626   // Set property for top level display mode
2627   QStringList aTopModesList;
2628   aTopModesList.append( tr("MEN_SHOW_ADD_WACTOR") );
2629   aTopModesList.append( tr("MEN_KEEP_CURRENT_DM") );
2630   aTopModesList.append( tr("MEN_WIREFRAME") );
2631   aTopModesList.append( tr("MEN_SHADING") );
2632   aTopModesList.append( tr("MEN_SHADING_WITH_EDGES") );
2633
2634   QList<QVariant> aTopIndexesList;
2635   aTopIndexesList.append(0);
2636   aTopIndexesList.append(1);
2637   aTopIndexesList.append(2);
2638   aTopIndexesList.append(3);
2639   aTopIndexesList.append(4);
2640
2641   setPreferenceProperty( top_lev_dm, "strings", aTopModesList );
2642   setPreferenceProperty( top_lev_dm, "indexes", aTopIndexesList );
2643
2644   // Set property for step value for spinboxes
2645   setPreferenceProperty( step, "min", 1 );
2646   setPreferenceProperty( step, "max", 10000 );
2647   setPreferenceProperty( step, "precision", 3 );
2648
2649   // Set property for trandparency value for spinboxes
2650   setPreferenceProperty( transparency, "min", 0 );
2651   setPreferenceProperty( transparency, "max", 100 );
2652
2653   // Set property for deflection value for spinboxes
2654   setPreferenceProperty( defl, "min", GEOM::minDeflection() );
2655   setPreferenceProperty( defl, "max", 1.0 );
2656   setPreferenceProperty( defl, "step", 1.0e-04 );
2657   setPreferenceProperty( defl, "precision", 6 );
2658
2659   // Set property for default material
2660   setPreferenceProperty( material, "strings", Material_ResourceMgr::resourceMgr()->materials() );
2661
2662   // Set property vertex marker type
2663   QList<QVariant> aMarkerTypeIndicesList;
2664   QList<QVariant> aMarkerTypeIconsList;
2665
2666   for ( int i = GEOM::MT_POINT; i < GEOM::MT_USER; i++ ) {
2667     QString icoFile = QString( "ICON_VERTEX_MARKER_%1" ).arg( i );
2668     QPixmap pixmap = resMgr->loadPixmap( "GEOM", tr( qPrintable( icoFile ) ) );
2669     aMarkerTypeIndicesList << (i-1);
2670     aMarkerTypeIconsList << pixmap;
2671   }
2672
2673   setPreferenceProperty( typeOfMarker, "indexes", aMarkerTypeIndicesList );
2674   setPreferenceProperty( typeOfMarker, "icons",   aMarkerTypeIconsList );
2675
2676   // Set property for vertex marker scale
2677   QList<QVariant> aMarkerScaleIndicesList;
2678   QStringList     aMarkerScaleValuesList;
2679
2680   for ( int iii = GEOM::MS_10; iii <= GEOM::MS_70; iii++ ) {
2681     aMarkerScaleIndicesList << iii;
2682     aMarkerScaleValuesList  << QString::number( (iii-(int)GEOM::MS_10)*0.5 + 1.0 );
2683   }
2684
2685   setPreferenceProperty( markerScale, "strings", aMarkerScaleValuesList );
2686   setPreferenceProperty( markerScale, "indexes", aMarkerScaleIndicesList );
2687
2688   // Scalar bar for field step presentation
2689   int scalarBarGroup = addPreference( tr( "PREF_GROUP_SCALAR_BAR" ), tabId );
2690   setPreferenceProperty( scalarBarGroup, "columns", 2 );
2691
2692   int sbXPosition = addPreference( tr( "PREF_SCALAR_BAR_X_POSITION" ), scalarBarGroup,
2693                                    LightApp_Preferences::DblSpin, "Geometry", "scalar_bar_x_position" );
2694   setPreferenceProperty( sbXPosition, "min", 0 );
2695   setPreferenceProperty( sbXPosition, "max", 1 );
2696   setPreferenceProperty( sbXPosition, "step", 0.05 );
2697
2698   int sbYPosition = addPreference( tr( "PREF_SCALAR_BAR_Y_POSITION" ), scalarBarGroup,
2699                                    LightApp_Preferences::DblSpin, "Geometry", "scalar_bar_y_position" );
2700   setPreferenceProperty( sbYPosition, "min", 0 );
2701   setPreferenceProperty( sbYPosition, "max", 1 );
2702   setPreferenceProperty( sbYPosition, "step", 0.05 );
2703
2704   int sbWidth = addPreference( tr( "PREF_SCALAR_BAR_WIDTH" ), scalarBarGroup,
2705                                LightApp_Preferences::DblSpin, "Geometry", "scalar_bar_width" );
2706   setPreferenceProperty( sbWidth, "min", 0 );
2707   setPreferenceProperty( sbWidth, "max", 1 );
2708   setPreferenceProperty( sbWidth, "step", 0.05 );
2709
2710   int sbHeight = addPreference( tr( "PREF_SCALAR_BAR_HEIGHT" ), scalarBarGroup,
2711                                 LightApp_Preferences::DblSpin, "Geometry", "scalar_bar_height" );
2712   setPreferenceProperty( sbHeight, "min", 0 );
2713   setPreferenceProperty( sbHeight, "max", 1 );
2714   setPreferenceProperty( sbHeight, "step", 0.05 );
2715
2716   int sbTextHeight = addPreference( tr( "PREF_SCALAR_BAR_TEXT_HEIGHT" ), scalarBarGroup,
2717                                     LightApp_Preferences::IntSpin, "Geometry", "scalar_bar_text_height" );
2718   setPreferenceProperty( sbTextHeight, "min", 6 );
2719   setPreferenceProperty( sbTextHeight, "max", 24 );
2720   setPreferenceProperty( sbTextHeight, "step", 1 );
2721
2722   int sbNbIntervals = addPreference( tr( "PREF_SCALAR_BAR_NUMBER_OF_INTERVALS" ), scalarBarGroup,
2723                                      LightApp_Preferences::IntSpin, "Geometry", "scalar_bar_nb_intervals" );
2724   setPreferenceProperty( sbNbIntervals, "min", 2 );
2725   setPreferenceProperty( sbNbIntervals, "max", 64 );
2726   setPreferenceProperty( sbNbIntervals, "step", 1 );
2727
2728   int originGroup = addPreference( tr( "PREF_GROUP_ORIGIN_AND_BASE_VECTORS" ), tabId );
2729   setPreferenceProperty( originGroup, "columns", 2 );
2730
2731   int baseVectorsLength = addPreference( tr( "PREF_BASE_VECTORS_LENGTH" ), originGroup,
2732                                          LightApp_Preferences::DblSpin, "Geometry", "base_vectors_length" );
2733   setPreferenceProperty( baseVectorsLength, "min", 0.01 );
2734   setPreferenceProperty( baseVectorsLength, "max", 1000 );
2735
2736   addPreference( tr( "PREF_AUTO_CREATE" ), originGroup,
2737                  LightApp_Preferences::Bool, "Geometry", "auto_create_base_objects" );
2738
2739   int operationsGroup = addPreference( tr( "PREF_GROUP_OPERATIONS" ), tabId );
2740   setPreferenceProperty( operationsGroup, "columns", 2 );
2741
2742   addPreference( tr( "GEOM_PREVIEW" ), operationsGroup,
2743                  LightApp_Preferences::Bool, "Geometry", "geom_preview" );
2744
2745   addPreference( tr( "PREF_HIDE_INPUT_OBJECT" ), operationsGroup,
2746                  LightApp_Preferences::Bool, "Geometry", "hide_input_object" );
2747
2748   int DependencyViewId = addPreference( tr( "PREF_TAB_DEPENDENCY_VIEW" ) );
2749
2750   int treeGeneralGroup = addPreference( tr( "PREF_GROUP_GENERAL" ), DependencyViewId );
2751
2752   int hierarchy_type = addPreference( tr( "PREF_HIERARCHY_TYPE" ), treeGeneralGroup,
2753                       LightApp_Preferences::Selector, "Geometry", "dependency_tree_hierarchy_type" );
2754
2755   QStringList aHierarchyTypeList;
2756   aHierarchyTypeList.append( tr("MEN_BOTH_ASCENDANTS_DESCENDANTS") );
2757   aHierarchyTypeList.append( tr("MEN_ONLY_ASCENDANTS") );
2758   aHierarchyTypeList.append( tr("MEN_ONLY_DESCENDANTS") );
2759
2760   QList<QVariant> aHierarchyTypeIndexesList;
2761   aHierarchyTypeIndexesList.append(0);
2762   aHierarchyTypeIndexesList.append(1);
2763   aHierarchyTypeIndexesList.append(2);
2764
2765   setPreferenceProperty( hierarchy_type, "strings", aHierarchyTypeList );
2766   setPreferenceProperty( hierarchy_type, "indexes", aHierarchyTypeIndexesList );
2767
2768   addPreference( tr( "GEOM_MOVE_POSSIBILITY" ), treeGeneralGroup,
2769                  LightApp_Preferences::Bool, "Geometry", "dependency_tree_move_nodes" );
2770
2771   int treeColorGroup = addPreference( tr( "PREF_GROUP_DEPENDENCY_VIEW_COLOR" ), DependencyViewId );
2772
2773   addPreference( tr( "PREF_DEPENDENCY_VIEW_BACKGROUND_COLOR"), treeColorGroup,
2774                  LightApp_Preferences::Color, "Geometry", "dependency_tree_background_color" );
2775
2776   addPreference( tr( "PREF_DEPENDENCY_VIEW_NODE_COLOR"), treeColorGroup,
2777                  LightApp_Preferences::Color, "Geometry", "dependency_tree_node_color" );
2778   addPreference( tr( "PREF_DEPENDENCY_VIEW_MAIN_NODE_COLOR"), treeColorGroup,
2779                  LightApp_Preferences::Color, "Geometry", "dependency_tree_main_node_color" );
2780   addPreference( tr( "PREF_DEPENDENCY_VIEW_UNPUBLISH_NODE_COLOR"), treeColorGroup,
2781                  LightApp_Preferences::Color, "Geometry", "dependency_tree_unpublish_node_color" );
2782   addPreference( tr( "PREF_DEPENDENCY_VIEW_SELECT_NODE_COLOR"), treeColorGroup,
2783                  LightApp_Preferences::Color, "Geometry", "dependency_tree_select_node_color" );
2784
2785   addPreference( tr( "PREF_DEPENDENCY_VIEW_ARROW_COLOR"), treeColorGroup,
2786                  LightApp_Preferences::Color, "Geometry", "dependency_tree_arrow_color" );
2787   addPreference( tr( "PREF_DEPENDENCY_VIEW_HIGHLIGHT_ARROW_COLOR"), treeColorGroup,
2788                  LightApp_Preferences::Color, "Geometry", "dependency_tree_highlight_arrow_color" );
2789   addPreference( tr( "PREF_DEPENDENCY_VIEW_SELECT_ARROW_COLOR"), treeColorGroup,
2790                  LightApp_Preferences::Color, "Geometry", "dependency_tree_select_arrow_color" );
2791
2792
2793
2794
2795 }
2796
2797 void GeometryGUI::preferencesChanged( const QString& section, const QString& param )
2798 {
2799   if (section == "Geometry") {
2800     SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
2801     if (param == QString("SettingsGeomStep")) {
2802       double spin_step = aResourceMgr->doubleValue(section, param, 100.);
2803       EmitSignalDefaultStepValueChanged(spin_step);
2804     }
2805     else if (param == QString("toplevel_color")) {
2806       QColor c = aResourceMgr->colorValue( "Geometry", "toplevel_color", QColor( 170, 85, 0 ) );
2807       GEOM_AISShape::setTopLevelColor(SalomeApp_Tools::color(c));
2808     }
2809     else if (param == QString("toplevel_dm")) {
2810       GEOM_AISShape::setTopLevelDisplayMode((GEOM_AISShape::TopLevelDispMode)aResourceMgr->integerValue("Geometry", "toplevel_dm", 0));
2811     }
2812     else if (param == QString("scalar_bar_x_position") ||
2813              param == QString("scalar_bar_y_position") ||
2814              param == QString("scalar_bar_width") ||
2815              param == QString("scalar_bar_height") ||
2816              param == QString("scalar_bar_text_height") ||
2817              param == QString("scalar_bar_nb_intervals")) {
2818       if( SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) )
2819       {
2820         updateFieldColorScale();
2821       }
2822     }
2823     else if ( param == QString("dimensions_color")            ||
2824               param == QString("dimensions_line_width")       ||
2825               param == QString("dimensions_font")             ||
2826               param == QString("dimensions_arrow_length")     ||
2827               param == QString("dimensions_show_units")       ||
2828               param == QString("dimensions_length_units")     ||
2829               param == QString("dimensions_angle_units")      ||
2830               param == QString("dimensions_use_text3d")       ||
2831               param == QString("shape_annotation_font_color") ||
2832               param == QString("shape_annotation_line_color") ||
2833               param == QString("shape_annotation_font")       ||
2834               param == QString("shape_annotation_line_width") ||
2835               param == QString("shape_annotation_autohide")   ||
2836               param == QString("shape_annotation_line_style") ||
2837               param == QString("shape_annotation_line_style") ||
2838               param == QString("label_color") )
2839     {
2840       SalomeApp_Application* anApp = getApp();
2841       if ( !anApp )
2842       {
2843         return;
2844       }
2845
2846       SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
2847       if ( !aStudy )
2848       {
2849         return;
2850       }
2851
2852       GEOM_Displayer aDisplayer( aStudy );
2853
2854       ViewManagerList aVMs;
2855       anApp->viewManagers( OCCViewer_Viewer::Type(), aVMs );
2856       ViewManagerList::Iterator anIt = aVMs.begin();
2857       for ( ; anIt != aVMs.end(); ++anIt )
2858       {
2859         SOCC_Viewer* aViewer = dynamic_cast<SOCC_Viewer*>( (*anIt)->getViewModel() );
2860         if ( !aViewer )
2861         {
2862           continue;
2863         }
2864
2865         SALOME_ListIO aVisible;
2866         aViewer->GetVisible( aVisible );
2867
2868         GEOMGUI_AnnotationMgr* anAnnotationMgr = GetAnnotationMgr();
2869         if ( anAnnotationMgr ) {
2870           SALOME_ListIteratorOfListIO anIter( aVisible );
2871           while ( anIter.More() ) {
2872             if ( anAnnotationMgr->isAnnotationEntry( anIter.Value()->getEntry() ) ) {
2873               aVisible.Remove( anIter );
2874             }
2875             else {
2876               anIter.Next();
2877             }
2878           }
2879         }
2880
2881         aDisplayer.Redisplay( aVisible, false, aViewer );
2882       }
2883       if ( param == QString( "label_color" ) ) {
2884         ViewManagerList aVMsVTK;
2885         anApp->viewManagers( SVTK_Viewer::Type(), aVMsVTK );
2886         ViewManagerList::Iterator anIt = aVMsVTK.begin();
2887         for ( ; anIt != aVMsVTK.end(); ++anIt )
2888         {
2889             SVTK_Viewer* aViewer = dynamic_cast<SVTK_Viewer*>( (*anIt)->getViewModel() );
2890             if ( !aViewer )
2891             {
2892               continue;
2893             }
2894             SALOME_ListIO aVisible;
2895             aViewer->GetVisible( aVisible );
2896             aDisplayer.Redisplay( aVisible, false, aViewer );
2897           }
2898       }
2899       aDisplayer.UpdateViewer();
2900     }
2901     else if ( param.startsWith( "dependency_tree") )
2902       emit SignalDependencyTreeParamChanged( section, param );
2903   }
2904 }
2905
2906 LightApp_Displayer* GeometryGUI::displayer()
2907 {
2908   if ( !myDisplayer )
2909     myDisplayer = new GEOM_Displayer( dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) );
2910   return myDisplayer;
2911 }
2912
2913 void GeometryGUI::setLocalSelectionMode(const int mode)
2914 {
2915   myLocalSelectionMode = mode;
2916 }
2917
2918 int GeometryGUI::getLocalSelectionMode() const
2919 {
2920   return myLocalSelectionMode;
2921 }
2922
2923 const char gSeparator = '_'; // character used to separate parameter names
2924 const char gDigitsSep = ':'; // character used to separate numeric parameter values (color = r:g:b)
2925
2926 /*!
2927  * \brief Store visual parameters
2928  *
2929  * This method is called just before the study document is saved.
2930  * Store visual parameters in AttributeParameter attribute(s)
2931  */
2932 void GeometryGUI::storeVisualParameters (int savePoint)
2933 {
2934   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
2935   if ( !appStudy || !appStudy->studyDS() )
2936     return;
2937
2938   _PTR(Study) studyDS = appStudy->studyDS();
2939
2940   // componentName is used for encoding of entries when storing them in IParameters
2941   std::string componentName = myComponentGeom->ComponentDataType();
2942   //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
2943   //if (!aSComponent) return;
2944
2945   // IParameters
2946   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
2947                                                              componentName.c_str(),
2948                                                              savePoint);
2949   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
2950
2951   QSet<QString> anEntriesToStoreShared;
2952   QList<SUIT_ViewManager*> lst;
2953   QList<SUIT_ViewManager*>::Iterator it;
2954
2955   GEOMGUI_AnnotationMgr* aAnnotationMgr = GetAnnotationMgr();
2956
2957   // main cycle to store parameters of displayed objects
2958   lst.clear();
2959   getApp()->viewManagers(lst);
2960   for (it = lst.begin(); it != lst.end(); it++) {
2961     SUIT_ViewManager* vman = *it;
2962     QString vType = vman->getType();
2963     SUIT_ViewModel* vmodel = vman->getViewModel();
2964     SALOME_View* aView = dynamic_cast<SALOME_View*>(vmodel);
2965
2966     int aMgrId = vman->getGlobalId();
2967     // saving VTK actors properties
2968     QVector<SUIT_ViewWindow*> views = vman->getViews();
2969     for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++) {
2970       const ObjMap& anObjects = appStudy->getObjectProperties(aMgrId);
2971       ObjMap::ConstIterator o_it = anObjects.begin();
2972       for (; o_it != anObjects.end(); o_it++) {
2973         const PropMap& aProps = o_it.value();
2974
2975         //Check that object exists in the study
2976         _PTR(SObject) obj( studyDS->FindObjectID( o_it.key().toLatin1().data() ) );
2977         if ( !obj || !(aProps.count() > 0))
2978           continue;
2979         // entry is "encoded" = it does NOT contain component address, since it is a
2980         // subject to change on next component loading
2981
2982         std::string entry = ip->encodeEntry(o_it.key().toLatin1().data(), componentName);
2983
2984         _PTR(GenericAttribute) anAttr;
2985         if (!obj->FindAttribute(anAttr, "AttributeIOR"))
2986           continue;
2987
2988         // remember entry of object to store shared GEOM properties
2989         // (e.g. dimension properties).
2990         if ( vType == OCCViewer_Viewer::Type() )
2991         {
2992           anEntriesToStoreShared.insert( o_it.key() );
2993         }
2994
2995         QString param, occParam = vType;
2996         occParam += GEOM::sectionSeparator();
2997         occParam += QString::number(aMgrId);
2998         occParam += GEOM::sectionSeparator();
2999
3000         if (aProps.contains(GEOM::propertyName( GEOM::Visibility ))) {
3001           param = occParam + GEOM::propertyName( GEOM::Visibility );
3002           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::Visibility )).toBool() ? "On" : "Off");
3003         }
3004
3005         if (aProps.contains(GEOM::propertyName( GEOM::DisplayMode ))) {
3006           param = occParam + GEOM::propertyName( GEOM::DisplayMode );
3007           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::DisplayMode )).toString().toStdString());
3008         }
3009
3010         if (aProps.contains(GEOM::propertyName( GEOM::Color ))) {
3011           QColor c = aProps.value(GEOM::propertyName( GEOM::Color )).value<QColor>();
3012           QStringList val;
3013           val << QString::number(c.redF());
3014           val << QString::number(c.greenF());
3015           val << QString::number(c.blueF());
3016           param = occParam + GEOM::propertyName( GEOM::Color );
3017           ip->setParameter(entry, param.toStdString(), val.join( GEOM::subSectionSeparator()).toStdString());
3018         }
3019         
3020         if (aProps.contains(GEOM::propertyName( GEOM::Texture ))) {
3021           param = occParam + GEOM::propertyName( GEOM::Texture );
3022           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::Texture )).toString().toStdString());
3023         }
3024
3025         if (vType == SVTK_Viewer::Type()) {
3026           if (aProps.contains(GEOM::propertyName( GEOM::Opacity ))) {
3027             param = occParam + GEOM::propertyName( GEOM::Opacity );
3028             ip->setParameter(entry, param.toStdString(), QString::number(1. - aProps.value(GEOM::propertyName( GEOM::Transparency )).toDouble()).toStdString());
3029           }
3030         } else if (vType == SOCC_Viewer::Type()) {
3031           if (aProps.contains(GEOM::propertyName( GEOM::Transparency ))) {
3032             param = occParam + GEOM::propertyName( GEOM::Transparency );
3033             ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::Transparency )).toString().toStdString());
3034           }
3035
3036           if (aProps.contains(GEOM::propertyName( GEOM::TopLevel ))) {
3037             param = occParam + GEOM::propertyName( GEOM::TopLevel );
3038             ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::TopLevel )).toString().toStdString());
3039           }
3040         }
3041
3042         if (aProps.contains(GEOM::propertyName( GEOM::NbIsos ))) {
3043           param = occParam + GEOM::propertyName( GEOM::NbIsos );
3044           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::NbIsos )).toString().toStdString());
3045         }
3046
3047         if (aProps.contains(GEOM::propertyName( GEOM::EdgesDirection ))) {
3048           param = occParam + GEOM::propertyName( GEOM::EdgesDirection );
3049           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::EdgesDirection )).toString().toStdString());
3050         }
3051
3052         if (aProps.contains(GEOM::propertyName( GEOM::Vertices ))) {
3053           param = occParam + GEOM::propertyName( GEOM::Vertices );
3054           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::Vertices )).toString().toStdString());
3055         }
3056
3057         if (aProps.contains(GEOM::propertyName( GEOM::ShowName ))) {
3058           param = occParam + GEOM::propertyName( GEOM::ShowName );
3059           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::ShowName )).toString().toStdString());
3060         }
3061
3062         if (aProps.contains(GEOM::propertyName( GEOM::Deflection ))) {
3063           param = occParam + GEOM::propertyName( GEOM::Deflection );
3064           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::Deflection )).toString().toStdString());
3065         }
3066
3067         //Marker type of the vertex - ONLY for the "Vertex" and "Compound of the Vertex"
3068         if (aProps.contains(GEOM::propertyName( GEOM::PointMarker ))) {
3069           param = occParam + GEOM::propertyName( GEOM::PointMarker );
3070           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::PointMarker )).toString().toStdString());
3071         }
3072
3073         if (aProps.contains(GEOM::propertyName( GEOM::Material ))) {
3074           param = occParam + GEOM::propertyName( GEOM::Material );
3075           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::Material )).toString().toStdString());
3076         }
3077
3078         if (aProps.contains(GEOM::propertyName( GEOM::LineWidth ))) {
3079              param = occParam + GEOM::propertyName( GEOM::LineWidth );
3080            ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::LineWidth )).toString().toStdString());
3081         }
3082
3083         if (aProps.contains(GEOM::propertyName( GEOM::IsosWidth ))) {
3084           param = occParam + GEOM::propertyName( GEOM::IsosWidth );
3085           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::IsosWidth )).toString().toStdString());
3086         }
3087
3088         if ( vType == SOCC_Viewer::Type() && aAnnotationMgr ) {
3089           std::string anAnnotationInfo = GetAnnotationMgr()->getDisplayedIndicesInfo(
3090                                             o_it.key().toLatin1().data(), dynamic_cast<SOCC_Viewer*>(aView) ).toStdString();
3091           if (!anAnnotationInfo.empty()) {
3092             param = occParam + "ShapeAnnotationVisibleItems";
3093             ip->setParameter(entry, param.toStdString(), anAnnotationInfo);
3094           }
3095         }
3096       } // object iterator
3097     } // for (views)
3098   } // for (viewManagers)
3099
3100   // store shape annotation and dimension attributes of objects:
3101   // since the displayed object always persists in property map, we remember the object entries
3102   // on the passes when we store viewer related properties - to avoid extra iterations on GEOM component tree.
3103   const QString aDimensionParam = OCCViewer_Viewer::Type() + GEOM::sectionSeparator() + GEOM::propertyName( GEOM::Dimensions );
3104   const QString aAnnotationParam = OCCViewer_Viewer::Type() + GEOM::sectionSeparator() + GEOM::propertyName( GEOM::ShapeAnnotations );
3105   QSet<QString>::ConstIterator aEntryIt = anEntriesToStoreShared.constBegin();
3106   for ( ; aEntryIt != anEntriesToStoreShared.constEnd(); ++aEntryIt )
3107   {
3108     std::string aStudyEntry = (*aEntryIt).toLatin1().data();
3109     std::string aStoreEntry = ip->encodeEntry( aStudyEntry, componentName );
3110
3111     // store dimension parameters
3112     GEOMGUI_DimensionProperty aDimensions( appStudy, aStudyEntry );
3113     if ( aDimensions.GetNumber() != 0 ) {
3114       ip->setParameter( aStoreEntry, aDimensionParam.toStdString(), ((QString)aDimensions).toLatin1().data() );
3115     }
3116
3117     _PTR(SObject) aObj( studyDS->FindObjectID( aStudyEntry ) );
3118     const Handle(GEOMGUI_AnnotationAttrs) aShapeAnnAttr = GEOMGUI_AnnotationAttrs::FindAttributes( aObj );
3119     if ( !aShapeAnnAttr.IsNull() ) {
3120       ip->setParameter( aStoreEntry, aAnnotationParam.toStdString(), aShapeAnnAttr->ExportAsPropertyString().toLatin1().data() );
3121     }
3122   }
3123 }
3124
3125 /*!
3126  * \brief Restore visual parameters
3127  *
3128  * This method is called after the study document is opened.
3129  * Restore visual parameters from AttributeParameter attribute(s)
3130  */
3131 void GeometryGUI::restoreVisualParameters (int savePoint)
3132 {
3133   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
3134   if (!appStudy || !appStudy->studyDS())
3135     return;
3136   _PTR(Study) studyDS = appStudy->studyDS();
3137
3138   // componentName is used for encoding of entries when storing them in IParameters
3139   std::string componentName = myComponentGeom->ComponentDataType();
3140   //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
3141   //if (!aSComponent) return;
3142
3143   // IParameters
3144   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
3145                                                              componentName.c_str(),
3146                                                              savePoint);
3147   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
3148
3149   std::vector<std::string> entries = ip->getEntries();
3150
3151   for (std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt)
3152   {
3153     // entry is a normal entry - it should be "decoded" (setting base address of component)
3154     QString entry (ip->decodeEntry(*entIt).c_str());
3155
3156     // Check that the entry corresponds to a real object in the Study
3157     // as the object may be deleted or modified after the visual state is saved.
3158     _PTR(SObject) so = studyDS->FindObjectID(entry.toLatin1().data());
3159     if (!so) continue; //Skip the not existent entry
3160
3161     std::vector<std::string> paramNames = ip->getAllParameterNames( *entIt );
3162     std::vector<std::string> paramValues = ip->getAllParameterValues( *entIt );
3163
3164     std::vector<std::string>::iterator namesIt = paramNames.begin();
3165     std::vector<std::string>::iterator valuesIt = paramValues.begin();
3166
3167     // actors are stored in a map after displaying of them for
3168     // quicker access in the future: map < viewID to actor >
3169     NCollection_DataMap<int, GEOM_Actor*          > vtkActors;
3170     NCollection_DataMap<int, Handle(GEOM_AISShape)> occActors;
3171
3172     QString viewerTypStr;
3173     QString viewIndexStr;
3174     int viewIndex;
3175     QVector<PropMap> aListOfMap;
3176
3177     for (; namesIt != paramNames.end(); ++namesIt, ++valuesIt)
3178     {
3179       // visual parameters are stored in strings as follows: 
3180       //   1) ViewerType_ViewIndex_ParamName
3181       //   2) ViewerType_ParamName (shared for GEOM module)
3182       // '_' is used as separator and should not be used in viewer type or parameter names.
3183       QStringList lst = QString((*namesIt).c_str()).split( GEOM::sectionSeparator(), QString::SkipEmptyParts);
3184
3185       bool isShared = lst.size() == 2;
3186       bool isViewer = lst.size() == 3;
3187       if ( !isShared && !isViewer )
3188       {
3189         continue;
3190       }
3191
3192       // shared visual parameters
3193       if ( isShared )
3194       {
3195         QString aParamNameStr( lst[1] );
3196         QString aValuesStr( (*valuesIt).c_str() );
3197
3198         // shared dimension properties are stored as attribute
3199         if ( aParamNameStr == GEOM::propertyName( GEOM::Dimensions ) )
3200         {
3201           GEOMGUI_DimensionProperty aDimensionProp( aValuesStr );
3202           aDimensionProp.SaveToAttribute( appStudy, entry.toLatin1().data() );
3203         }
3204         else if ( aParamNameStr == GEOM::propertyName( GEOM::ShapeAnnotations ) )
3205         {
3206           Handle(GEOMGUI_AnnotationAttrs) anAttr =
3207             GEOMGUI_AnnotationAttrs::FindOrCreateAttributes( so, appStudy );
3208
3209           anAttr->ImportFromPropertyString( aValuesStr );
3210         }
3211
3212         continue;
3213       }
3214
3215       // per view visual parameters
3216       viewerTypStr = lst[0];
3217       viewIndexStr = lst[1];
3218       QString paramNameStr = lst[2];
3219
3220       bool ok;
3221       viewIndex = viewIndexStr.toUInt(&ok);
3222       if (!ok) // bad conversion of view index to integer
3223         continue;
3224
3225       if ((viewIndex + 1) > aListOfMap.count()) {
3226         aListOfMap.resize(viewIndex + 1);
3227       }
3228
3229       QString val((*valuesIt).c_str());
3230       if (paramNameStr == GEOM::propertyName( GEOM::Visibility )) {
3231         aListOfMap[viewIndex].insert(GEOM::propertyName( GEOM::Visibility ), val == "On");
3232       } else if (paramNameStr == GEOM::propertyName( GEOM::Opacity )) {
3233         aListOfMap[viewIndex].insert(GEOM::propertyName( GEOM::Transparency ), 1. - val.toDouble());
3234       } else if (paramNameStr == GEOM::propertyName( GEOM::Transparency )) {
3235         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::Transparency ), val.toDouble() );
3236       } else if (paramNameStr == GEOM::propertyName( GEOM::TopLevel )) {
3237         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::TopLevel ), val == "true" || val == "1");
3238       } else if (paramNameStr == GEOM::propertyName( GEOM::DisplayMode )) {
3239         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::DisplayMode ), val.toInt());
3240       } else if (paramNameStr == GEOM::propertyName( GEOM::NbIsos )) {
3241         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::NbIsos ), val);
3242       } else if (paramNameStr == GEOM::propertyName( GEOM::Color )) {
3243         QStringList rgb = val.split(GEOM::subSectionSeparator());
3244         if (rgb.count() == 3) {
3245           QColor c = QColor::fromRgbF(rgb[0].toDouble(), rgb[1].toDouble(), rgb[2].toDouble());
3246           aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::Color ), c);
3247         }
3248       } else if (paramNameStr == GEOM::propertyName( GEOM::Texture )) {
3249         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::Texture ), val );
3250       } else if (paramNameStr == GEOM::propertyName( GEOM::EdgesDirection )) {
3251         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::EdgesDirection ), val == "true" || val == "1");
3252       } else if (paramNameStr == GEOM::propertyName( GEOM::Vertices )) {
3253         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::Vertices ), val == "true" || val == "1");
3254       } else if (paramNameStr == GEOM::propertyName( GEOM::ShowName )) {
3255         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::ShowName ), val == "true" || val == "1");
3256       } else if (paramNameStr == GEOM::propertyName( GEOM::Deflection )) {
3257         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::Deflection ), val.toDouble());
3258       } else if (paramNameStr == GEOM::propertyName( GEOM::PointMarker )) {
3259         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::PointMarker ), val);
3260       } else if (paramNameStr == GEOM::propertyName( GEOM::Material )) {
3261         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::Material ), val);
3262       } else if (paramNameStr == GEOM::propertyName( GEOM::LineWidth )) {
3263         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::LineWidth ), val.toInt());
3264       } else if (paramNameStr == GEOM::propertyName( GEOM::IsosWidth )) {
3265         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::IsosWidth ), val.toInt());
3266       } else if (paramNameStr == "ShapeAnnotationVisibleItems") {
3267         aListOfMap[viewIndex].insert( "ShapeAnnotationVisibleItems", val);
3268       }
3269
3270     } // for names/parameters iterator
3271
3272     QList<SUIT_ViewManager*> lst = getApp()->viewManagers();
3273
3274     for (int index = 0; index < aListOfMap.count(); index++) {
3275       appStudy->setObjectProperties(index, entry, aListOfMap[index]);
3276
3277       //Get Visibility property of the current PropMap
3278       if (aListOfMap[index].value(GEOM::propertyName( GEOM::Visibility )) == 1) {
3279         SUIT_ViewManager* vman = lst.at(index);
3280         SUIT_ViewModel* vmodel = vman->getViewModel();
3281         SALOME_View* aView = dynamic_cast<SALOME_View*>(vmodel);
3282         displayer()->Display(entry, true, aView);
3283
3284         if ( vmodel->getType() == SOCC_Viewer::Type() ) {
3285           PropMap& aProps = aListOfMap[index];
3286           if ( aProps.contains( "ShapeAnnotationVisibleItems" ) ) {
3287             SOCC_Viewer* aSOCCView = dynamic_cast<SOCC_Viewer*>( aView );
3288             GetAnnotationMgr()->setDisplayedIndicesInfo( entry, aSOCCView, aProps["ShapeAnnotationVisibleItems"].toString() );
3289           }
3290         }
3291       }
3292     }
3293   } // for entries iterator
3294
3295   // update all VTK and OCC views
3296   QList<SUIT_ViewManager*> lst;
3297   getApp()->viewManagers(lst);
3298   for (QList<SUIT_ViewManager*>::Iterator it = lst.begin(); it != lst.end(); it++) {
3299     SUIT_ViewModel* vmodel = (*it)->getViewModel();
3300     if (!vmodel)
3301       continue;
3302     if (vmodel->getType() == SVTK_Viewer::Type()) {
3303       SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) (*it)->getActiveView();
3304       vtkView->getRenderer()->ResetCameraClippingRange();
3305       vtkView->Repaint();
3306     }
3307     else if (vmodel->getType() == SOCC_Viewer::Type()) {
3308       //SOCC_ViewWindow* occView = (SOCC_ViewWindow*) (*it)->getActiveView();
3309       SALOME_View* occVMod = dynamic_cast<SALOME_View*>(vmodel);
3310       if (occVMod)
3311         occVMod->Repaint();
3312     }
3313   }
3314
3315   if ( myTextTreeWdg ) {
3316     myTextTreeWdg->updateTree();
3317   }
3318 }
3319
3320 // Compute current name mode of the viewer
3321 void UpdateNameMode( SalomeApp_Application* app )
3322 {
3323   bool isMode = false;
3324   SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
3325   SUIT_ViewWindow* viewWindow = app->desktop()->activeWindow();
3326   GEOM_Displayer displayer( aStudy );
3327   int aMgrId = viewWindow->getViewManager()->getGlobalId();
3328
3329   SALOME_View* window = displayer.GetActiveView();
3330   if ( !window ) return;
3331
3332   SALOME_ListIO anIOlst;
3333   window->GetVisible( anIOlst );
3334
3335   for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
3336     Handle( SALOME_InteractiveObject ) io = It.Value();
3337     QVariant v = aStudy->getObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::ShowName ), QVariant() );
3338     bool isIONameMode =  v.isValid() ? v.toBool() : false;
3339     if( isIONameMode )
3340       isMode = true;
3341   }
3342   viewWindow->setProperty( "NameMode", isMode );
3343 }
3344
3345 void GeometryGUI::onViewAboutToShow()
3346 {
3347   SUIT_ViewWindow* window = application()->desktop()->activeWindow();
3348   QAction* a = action( GEOMOp::OpSwitchVectors );
3349   QAction* aVerticesAction = action( GEOMOp::OpSwitchVertices );
3350   QAction* aNameAction = action( GEOMOp::OpSwitchName );
3351   if ( window ) {
3352     a->setEnabled(true);
3353     bool vmode = window->property("VectorsMode").toBool();
3354     a->setText ( vmode == 1 ? tr( "MEN_VECTOR_MODE_OFF" ) : tr("MEN_VECTOR_MODE_ON") );
3355     aVerticesAction->setEnabled(true);
3356     vmode = window->property("VerticesMode").toBool();
3357     aVerticesAction->setText ( vmode == 1 ? tr( "MEN_VERTICES_MODE_OFF" ) : tr("MEN_VERTICES_MODE_ON") );
3358     UpdateNameMode( getApp() );
3359     aNameAction->setEnabled(true);
3360     vmode = window->property("NameMode").toBool();
3361     aNameAction->setText ( vmode == 1 ? tr( "MEN_NAME_MODE_OFF" ) : tr("MEN_NAME_MODE_ON") );
3362   } else {
3363     a->setText ( tr("MEN_VECTOR_MODE_ON") );
3364     a->setEnabled(false);
3365     aVerticesAction->setText ( tr("MEN_VERTICES_MODE_ON") );
3366     aVerticesAction->setEnabled(false);
3367     aNameAction->setText ( tr("MEN_NAME_MODE_ON") );
3368     aNameAction->setEnabled(false);
3369   }
3370 }
3371
3372 /*!
3373   \brief Return action by id
3374   \param id identifier of the action
3375   \return action
3376 */
3377 QAction* GeometryGUI::getAction(const int id) {
3378   return action(id);
3379 }
3380
3381 /*!
3382   \brief GEOM module message handler
3383
3384   This method can be re-implemented in the subclasses.
3385   This is a GEOM module message handler.
3386
3387   \param msg the message received.
3388 */
3389 void GeometryGUI::message(const QString& msg)
3390 {
3391   // dispatch message
3392   QStringList data = msg.split("/");
3393   const int nbStrings = data.count();
3394
3395   if (nbStrings > 0) {
3396     if (data[0] == "modified") {
3397       // get mesh entry
3398       QString anIOR = nbStrings > 1 ? data[1] : QString();
3399
3400       if ( anIOR.isEmpty() ) {
3401         return;
3402       }
3403
3404       // Get the geom object.
3405       GEOM::GEOM_Object_ptr anObj = GeometryGUI::GetObjectFromIOR (anIOR);
3406
3407       // Clear the shape buffer
3408       GeometryGUI::ClearShapeBuffer (anObj);
3409     }
3410   }
3411 }
3412
3413 /*!
3414   \brief Clears the shape buffer.
3415
3416   This is a static method. It clears the shape buffer.
3417
3418   \param theObj the object
3419 */
3420 void GeometryGUI::ClearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
3421 {
3422   if ( CORBA::is_nil( theObj ) )
3423     return;
3424
3425   CORBA::String_var IOR = SalomeApp_Application::orb()->object_to_string( theObj );
3426   TCollection_AsciiString asciiIOR( (char *)IOR.in() );
3427   GEOM_Client::get_client().RemoveShapeFromBuffer( asciiIOR );
3428
3429   SALOMEDSClient_StudyManager *aManager = SalomeApp_Application::studyMgr();
3430
3431   if (!aManager)
3432     return;
3433
3434   _PTR(Study) aStudy = aManager->GetStudyByID(theObj->GetStudyID());
3435
3436   if ( !aStudy )
3437     return;
3438
3439   _PTR(SObject) aSObj ( aStudy->FindObjectIOR( std::string( IOR ) ) );
3440   if ( !aSObj )
3441     return;
3442
3443   _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
3444   for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
3445     _PTR(GenericAttribute) anAttr;
3446     if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) {
3447       _PTR(AttributeIOR) anIOR ( anAttr );
3448       TCollection_AsciiString asciiIOR( (char*)anIOR->Value().c_str() );
3449       GEOM_Client::get_client().RemoveShapeFromBuffer( asciiIOR );
3450     }
3451   }
3452 }
3453
3454 /*!
3455   \brief Returns the object from IOR.
3456
3457   This is a static method. It returns the object from its IOR.
3458
3459   \param IOR object IOR
3460   \return GEOM object.
3461 */
3462 GEOM::GEOM_Object_ptr GeometryGUI::GetObjectFromIOR( const QString& IOR )
3463 {
3464   GEOM::GEOM_Object_var geomObj;
3465   if ( !IOR.isEmpty() ) {
3466     CORBA::Object_var corbaObj = SalomeApp_Application::orb()->string_to_object
3467       ( IOR.toLatin1().constData() );
3468     if ( !CORBA::is_nil( corbaObj ) )
3469       geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
3470   }
3471   return geomObj._retn();
3472 }
3473
3474 /*!
3475   \brief Returns IOR of the object.
3476
3477   This is a static method. It returns the object's IOR.
3478
3479   \param object the GEOM object.
3480   \return object's IOR.
3481 */
3482 QString GeometryGUI::GetIORFromObject( GEOM::GEOM_Object_ptr object )
3483 {
3484   QString IOR;
3485   if ( !CORBA::is_nil( object ) ) {
3486     CORBA::String_var anIOR =
3487       SalomeApp_Application::orb()->object_to_string( object );
3488     IOR = anIOR.in();
3489   }
3490   return IOR;
3491 }
3492
3493 /*!
3494   \brief Check if this object is can't be renamed in place
3495
3496   This method can be re-implemented in the subclasses.
3497   Return true in case if object isn't reference or component (module root).
3498
3499   \param entry column id
3500   \return \c true if the item can be renamed by the user in place (e.g. in the Object browser)
3501 */
3502 bool GeometryGUI::renameAllowed( const QString& entry) const {
3503
3504   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
3505   SalomeApp_Study* appStudy = app ? dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) : 0;
3506   SalomeApp_DataObject* obj = appStudy ? dynamic_cast<SalomeApp_DataObject*>(appStudy->findObjectByEntry(entry)) : 0;
3507
3508   return (app && appStudy && obj && !appStudy->isComponent(entry) && !obj->isReference());
3509 }
3510
3511 /*!
3512   Rename object by entry.
3513   \param entry entry of the object
3514   \param name new name of the object
3515   \brief Return \c true if rename operation finished successfully, \c false otherwise.
3516 */
3517 bool GeometryGUI::renameObject( const QString& entry, const QString& name)
3518 {
3519   bool result = false;
3520
3521   SalomeApp_Application* app =
3522     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication());
3523   SalomeApp_Study* appStudy = app ? dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) : 0;
3524
3525   if (!appStudy)
3526     return result;
3527
3528   _PTR(Study) aStudy = appStudy->studyDS();
3529
3530   if (!aStudy)
3531     return result;
3532
3533   bool aLocked = (_PTR(AttributeStudyProperties)(appStudy->studyDS()->GetProperties()))->IsLocked();
3534   if ( aLocked ) {
3535     SUIT_MessageBox::warning ( app->desktop(), QObject::tr("WRN_WARNING"), QObject::tr("WRN_STUDY_LOCKED") );
3536     return result;
3537   }
3538
3539   _PTR(SObject) obj ( aStudy->FindObjectID(qPrintable(entry)) );
3540   _PTR(GenericAttribute) anAttr;
3541   if ( obj ) {
3542     if ( obj->FindAttribute(anAttr, "AttributeName") ) {
3543       _PTR(AttributeName) aName (anAttr);
3544
3545       aName->SetValue( name.toLatin1().data() ); // rename the SObject
3546       GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(obj));
3547       if (!CORBA::is_nil(anObj)) {
3548         anObj->SetName( name.toLatin1().data() );  // Rename the corresponding GEOM_Object
3549         emit SignalDependencyTreeRenameObject( anObj->GetEntry() );
3550         emit SignalTextTreeRenameObject( entry );
3551       }
3552       result = true;
3553     }
3554   }
3555   return result;
3556 }
3557
3558 void GeometryGUI::updateMaterials()
3559 {
3560   LightApp_Preferences* pref = preferences();
3561   if ( pref ) {
3562     QStringList materials = Material_ResourceMgr::resourceMgr()->materials();
3563     QString currentMaterial = SUIT_Session::session()->resourceMgr()->stringValue( "Geometry", "material" );
3564     if ( !materials.contains( currentMaterial ) )
3565       // user material set as default in the preferences, might be removed
3566       SUIT_Session::session()->resourceMgr()->setValue( "Geometry", "material", QString( "Plastic" ) );
3567
3568     QtxPreferenceItem* prefItem = pref->rootItem()->findItem( tr( "PREF_MATERIAL" ), true );
3569     if ( prefItem ) {
3570       setPreferenceProperty( prefItem->id(),
3571                              "strings", materials );
3572       prefItem->retrieve();
3573     }
3574   }
3575 }
3576
3577 /*!
3578   \brief Check if the module allows "drag" operation of its objects.
3579
3580   Overloaded from LightApp_Module class.
3581   
3582   This function is a part of the general drag-n-drop mechanism.
3583   The goal of this function is to check data object passed as a parameter
3584   and decide if it can be dragged or no.
3585
3586   \param what data object being tested for drag operation
3587   \return \c true if module allows dragging of the specified object
3588   \sa isDropAccepted(), dropObjects()
3589 */
3590 bool GeometryGUI::isDraggable( const SUIT_DataObject* what ) const
3591 {
3592   // we allow dragging object under root and object from folder
3593   int aLevel = what->level();
3594   bool anObjectInFolder = false;
3595   if ( aLevel > 2 ) {
3596     const SalomeApp_DataObject* dataObj = dynamic_cast<const SalomeApp_DataObject*>( what );
3597     if ( dataObj ) {
3598       _PTR(SObject) aSO = dataObj->object();
3599       if ( aSO ) {
3600         _PTR(GenericAttribute) anAttr;
3601         _PTR(SObject) aFatherSO = aSO->GetStudy()->GetUseCaseBuilder()->GetFather( aSO );
3602         if ( aFatherSO && aFatherSO->FindAttribute(anAttr, "AttributeLocalID") ) {
3603           _PTR(AttributeLocalID) aLocalID( anAttr );
3604           anObjectInFolder = aLocalID->Value() == 999;
3605         }
3606       }
3607     }
3608   }
3609   return aLevel == 2 || anObjectInFolder;
3610 }
3611
3612 /*!
3613   \brief Check if the module allows "drop" operation on the given object.
3614
3615   Overloaded from LightApp_Module class.
3616
3617   This function is a part of the general drag-n-drop mechanism.
3618   The goal of this function is to check data object passed as a parameter
3619   and decide if it can be used as a target for the "drop" operation.
3620   The processing of the drop operation itself is done in the dropObjects() function.
3621
3622   \param where target data object
3623   \return \c true if module supports dropping on the \a where data object
3624   \sa isDraggable(), dropObjects()
3625 */
3626 bool GeometryGUI::isDropAccepted( const SUIT_DataObject* where ) const
3627 {
3628   // we allow dropping into folder and top-level GEOM object
3629   int aLevel = where->level();
3630   bool isFolder = false;
3631   if ( aLevel > 1 ) {
3632     const SalomeApp_DataObject* dataObj = dynamic_cast<const SalomeApp_DataObject*>( where );
3633     if ( dataObj ) {
3634       _PTR(SObject) aSO = dataObj->object();
3635       if ( aSO ) {
3636         _PTR(GenericAttribute) anAttr;
3637         if ( aSO->FindAttribute(anAttr, "AttributeLocalID") ) {
3638           _PTR(AttributeLocalID) aLocalID( anAttr );
3639           isFolder = aLocalID->Value() == 999;
3640         }
3641       }
3642     }
3643   }
3644   return aLevel == 1 || isFolder;
3645 }
3646
3647 /*!
3648   \brief Complete drag-n-drop operation.
3649   
3650   Overloaded from LightApp_Module class.
3651
3652   This function is a part of the general drag-n-drop mechanism.
3653   Its goal is to handle dropping of the objects being dragged according
3654   to the chosen operation (move). The dropping is performed in the
3655   context of the parent data object \a where and the \a row (position in the 
3656   children index) at which the data should be dropped. If \a row is equal to -1,
3657   this means that objects are added to the end of the children list.
3658
3659   \param what objects being dropped
3660   \param where target data object
3661   \param row child index at which the drop operation is performed
3662   \param action drag-n-drop operation (Qt::DropAction) - move
3663
3664   \sa isDraggable(), isDropAccepted()
3665 */
3666 void GeometryGUI::dropObjects( const DataObjectList& what, SUIT_DataObject* where,
3667                                const int row, Qt::DropAction action )
3668 {
3669   if (action != Qt::CopyAction && action != Qt::MoveAction)
3670     return; // unsupported action
3671
3672   // get parent object
3673   SalomeApp_DataObject* dataObj = dynamic_cast<SalomeApp_DataObject*>( where );
3674   if ( !dataObj ) return; // wrong parent
3675   _PTR(SObject) parentObj = dataObj->object();
3676
3677   // Find the current Study and StudyBuilder
3678   _PTR(Study) aStudy = parentObj->GetStudy();
3679   _PTR(UseCaseBuilder) aUseCaseBuilder = aStudy->GetUseCaseBuilder();
3680   // collect all parents of the target node
3681   QStringList parentIDs;
3682   _PTR(SObject) parent = parentObj;
3683   while( !parent->IsNull() ) {
3684     parentIDs << parent->GetID().c_str();
3685     parent = aUseCaseBuilder->GetFather(parent);
3686   }
3687
3688   // collect objects being dropped
3689   GEOM::object_list_var objects = new GEOM::object_list();
3690   objects->length( what.count() );
3691   int count = 0;
3692   for ( int i = 0; i < what.count(); i++ ) {
3693     dataObj = dynamic_cast<SalomeApp_DataObject*>( what[i] );
3694     if ( !dataObj ) continue;  // skip wrong objects
3695     _PTR(SObject) sobj = dataObj->object();
3696     // check that dropped object is not a parent of target object
3697     if ( parentIDs.contains( sobj->GetID().c_str() ) ) {
3698       return; // it's not allowed to move node into it's child 
3699     }
3700     objects[i] = _CAST(SObject, sobj)->GetSObject();
3701     count++;
3702   }
3703   objects->length( count );
3704
3705   // call engine function
3706   GetGeomGen()->Move( objects.in(),                              // what
3707                       _CAST(SObject, parentObj)->GetSObject(),   // where
3708                       row );                                     // row
3709
3710   // update Object browser
3711   getApp()->updateObjectBrowser( false );
3712 }
3713
3714 void GeometryGUI::emitDimensionsUpdated( QString entry )
3715 {
3716   emit DimensionsUpdated( entry );
3717 }
3718
3719 void GeometryGUI::emitAnnotationsUpdated( QString entry )
3720 {
3721   emit SignalAnnotationsUpdated( entry );
3722 }