]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMGUI/GeometryGUI.cxx
Salome HOME
5470bbe2e61f3a97a955a25e86abf803bd4a4d47
[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 was occured!!!");
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() ) );
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 - COMPUND
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* ) ) );
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() ));
1878   connect( sm, SIGNAL( currentSelectionChanged() ), this, SLOT( onAutoBringToFront() ));
1879   connect( sm, SIGNAL( currentSelectionChanged() ), this, SLOT( updateFieldColorScale() ));
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() ) );
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 aDisplayer( aStudy );
2216     aDisplayer.UpdateColorScale();
2217   }
2218 }
2219
2220 QString GeometryGUI::engineIOR() const
2221 {
2222   if ( !CORBA::is_nil( GetGeomGen() ) )
2223     return QString( getApp()->orb()->object_to_string( GetGeomGen() ) );
2224   return "";
2225 }
2226
2227 Handle(TColStd_HArray1OfByte) GeometryGUI::getTexture
2228       (SalomeApp_Study* theStudy, int theId, int& theWidth, int& theHeight)
2229 {
2230   theWidth = theHeight = 0;
2231
2232   Handle(TColStd_HArray1OfByte) aTexture;
2233
2234   if (theStudy) {
2235     TextureMap aTextureMap = myTextureMap[ theStudy->studyDS()->StudyId() ];
2236     aTexture = aTextureMap[ theId ];
2237     if ( aTexture.IsNull() ) {
2238       GEOM::GEOM_IInsertOperations_var aInsOp = GeometryGUI::GetGeomGen()->GetIInsertOperations( theStudy->studyDS()->StudyId() );
2239       if ( !aInsOp->_is_nil() ) {
2240         CORBA::Long aWidth, aHeight;
2241         SALOMEDS::TMPFile_var aStream = aInsOp->GetTexture( theId, aWidth, aHeight );
2242         if ( aWidth > 0 && aHeight > 0 && aStream->length() > 0 ) {
2243           theWidth  = aWidth;
2244           theHeight = aHeight;
2245
2246           aTexture  = new TColStd_HArray1OfByte (1, aStream->length());
2247
2248           for ( CORBA::ULong i = 0; i < aStream->length(); i++)
2249             aTexture->SetValue( i+1, (Standard_Byte)aStream[i] );
2250           aTextureMap[ theId ] = aTexture;
2251         }
2252       }
2253     }
2254   }
2255   return aTexture;
2256 }
2257
2258 LightApp_Selection* GeometryGUI::createSelection() const
2259 {
2260   return new GEOMGUI_Selection();
2261 }
2262
2263 void GeometryGUI::contextMenuPopup( const QString& client, QMenu* menu, QString& title )
2264 {
2265   SalomeApp_Module::contextMenuPopup( client, menu, title );
2266   SALOME_ListIO lst;
2267   getApp()->selectionMgr()->selectedObjects( lst );
2268
2269   //Add submenu for predefined materials
2270   bool isPredefMat = SUIT_Session::session()->resourceMgr()->booleanValue( "Geometry", "predef_materials" );
2271   if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() > 0 ) {
2272     QtxPopupMgr* mgr = popupMgr();
2273     //get parrent for submenu
2274     QAction* act = mgr->action( mgr->actionId( action(  GEOMOp::OpMaterialProperties ) ) );
2275     //Clear old  menu
2276     QMenu* oldMenu = act->menu() ;
2277     if( oldMenu ) {
2278       delete oldMenu;
2279     }
2280     if( isPredefMat ){
2281       QMenu* matMenu = new QMenu();
2282       QSignalMapper* signalMapper = new QSignalMapper( matMenu );
2283
2284       //Get current material model for the object
2285       QVariant v;
2286       LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( getApp() );
2287       if ( anApp && anApp->activeViewManager() ) {
2288         LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( anApp->activeStudy() );
2289         if( aStudy ) {
2290           v = aStudy->getObjectProperty( anApp->activeViewManager()->getGlobalId(), lst.Last()->getEntry(), GEOM::propertyName( GEOM::Material ), QVariant() );
2291         }
2292       }
2293       QString curModel = "";
2294       if ( v.canConvert<QString>() ) curModel = v.toString();
2295       // get list of all predefined materials
2296       QStringList materials = Material_ResourceMgr::resourceMgr()->materials();
2297       bool found = false;
2298       foreach ( QString material, materials )
2299       {
2300         QAction* menAct = matMenu->addAction( material );
2301         connect(menAct, SIGNAL( toggled( bool ) ), signalMapper, SLOT( map() ) );
2302         signalMapper->setMapping( menAct, material );
2303         menAct->setCheckable( true );
2304         // Set checked if this material is current
2305         Material_Model aModel;
2306         aModel.fromResources( material );
2307         if ( !found && aModel.toProperties() == curModel ) {
2308           menAct->setChecked( true );
2309           found = true;
2310         }
2311       }
2312       matMenu->insertAction( matMenu->addSeparator(), action(  GEOMOp::OpPredefMaterCustom ) );
2313       matMenu->insertSeparator( action(  GEOMOp::OpPredefMaterCustom ) );
2314       connect( signalMapper, SIGNAL( mapped( const QString & ) ),
2315                  this, SLOT( OnSetMaterial( const QString & ) ) );
2316       act->setMenu( matMenu );
2317     }
2318   }
2319   //Set name
2320   if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
2321     Handle(SALOME_InteractiveObject) io = lst.First();
2322     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
2323     _PTR(Study) study = appStudy->studyDS();
2324     _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
2325     if ( obj ) {
2326       QString aName = QString( obj->GetName().c_str() );
2327       aName.remove( QRegExp("\\s+$") );
2328       title = aName;
2329     }
2330   }
2331 }
2332
2333 void GeometryGUI::OnSetMaterial(const QString& theName)
2334 {
2335   OnGUIEvent( GEOMOp::OpPredefMaterial, QVariant( theName ) );
2336 }
2337
2338
2339 void GeometryGUI::createPreferences()
2340 {
2341   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2342
2343   int tabId = addPreference( tr( "PREF_TAB_SETTINGS" ) );
2344
2345   int genGroup = addPreference( tr( "PREF_GROUP_GENERAL" ), tabId );
2346   setPreferenceProperty( genGroup, "columns", 2 );
2347
2348   int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), genGroup,
2349                                 LightApp_Preferences::Selector,
2350                                 "Geometry", "display_mode" );
2351
2352   addPreference( tr( "PREF_SHADING_COLOR" ), genGroup,
2353                  LightApp_Preferences::Color, "Geometry", "shading_color" );
2354
2355   addPreference( tr( "PREF_EDGES_IN_SHADING" ), genGroup,
2356                  LightApp_Preferences::Color, "Geometry", "edges_in_shading_color" );
2357
2358   addPreference( tr( "PREF_WIREFRAME_COLOR" ), genGroup,
2359                  LightApp_Preferences::Color, "Geometry", "wireframe_color" );
2360
2361   addPreference( tr( "PREF_FREE_BOUND_COLOR" ), genGroup,
2362                  LightApp_Preferences::Color, "Geometry", "free_bound_color" );
2363
2364   addPreference( tr( "PREF_LINE_COLOR"), genGroup,
2365                  LightApp_Preferences::Color, "Geometry", "line_color" );
2366
2367   addPreference( tr( "PREF_POINT_COLOR"), genGroup,
2368                  LightApp_Preferences::Color, "Geometry", "point_color" );
2369
2370   addPreference( tr( "PREF_ISOS_COLOR" ), genGroup,
2371                  LightApp_Preferences::Color, "Geometry", "isos_color" );
2372
2373   addPreference( tr( "PREF_LABEL_COLOR" ), genGroup,
2374                  LightApp_Preferences::Color, "Geometry", "label_color" );
2375
2376   addPreference( "", genGroup, LightApp_Preferences::Space );
2377
2378   addPreference( tr( "PREF_TOPLEVEL_COLOR" ), genGroup,
2379                  LightApp_Preferences::Color, "Geometry", "toplevel_color" );
2380
2381   int top_lev_dm = addPreference( tr( "PREF_TOPLEVEL_DM" ), genGroup,
2382                       LightApp_Preferences::Selector, "Geometry", "toplevel_dm" );
2383
2384   int transparency = addPreference( tr( "PREF_TRANSPARENCY" ), genGroup,
2385                                     LightApp_Preferences::IntSpin, "Geometry", "transparency" );
2386
2387   int defl = addPreference( tr( "PREF_DEFLECTION" ), genGroup,
2388                             LightApp_Preferences::DblSpin, "Geometry", "deflection_coeff" );
2389
2390   addPreference( tr( "PREF_PREDEF_MATERIALS" ), genGroup,
2391                  LightApp_Preferences::Bool, "Geometry", "predef_materials" );
2392
2393   int material = addPreference( tr( "PREF_MATERIAL" ), genGroup,
2394                                 LightApp_Preferences::Selector,
2395                                 "Geometry", "material" );
2396
2397   addPreference( tr( "PREF_EDITGROUP_COLOR" ), genGroup,
2398                  LightApp_Preferences::Color, "Geometry", "editgroup_color" );
2399
2400   const int nb = 4;
2401   int wd[nb];
2402   int iter=0;
2403
2404   wd[iter++] = addPreference( tr( "PREF_EDGE_WIDTH" ), genGroup,
2405                               LightApp_Preferences::IntSpin, "Geometry", "edge_width" );
2406
2407   wd[iter++] = addPreference( tr( "PREF_ISOLINES_WIDTH" ), genGroup,
2408                               LightApp_Preferences::IntSpin, "Geometry", "isolines_width" );
2409
2410   wd[iter++] = addPreference( tr( "PREF_PREVIEW_EDGE_WIDTH" ), genGroup,
2411                                      LightApp_Preferences::IntSpin, "Geometry", "preview_edge_width" );
2412
2413   wd[iter++] = addPreference( tr( "PREF_MEASURES_LINE_WIDTH" ), genGroup,
2414                               LightApp_Preferences::IntSpin, "Geometry", "measures_line_width" );
2415
2416   for (int i = 0; i < nb; i++) {
2417     setPreferenceProperty( wd[i], "min", 1 );
2418     setPreferenceProperty( wd[i], "max", 5 );
2419   }
2420
2421   int step = addPreference( tr( "PREF_STEP_VALUE" ), genGroup,
2422                             LightApp_Preferences::IntSpin, "Geometry", "SettingsGeomStep" );
2423
2424   addPreference( tr( "PREF_AUTO_BRING_TO_FRONT" ), genGroup,
2425                  LightApp_Preferences::Bool, "Geometry", "auto_bring_to_front" );
2426
2427   // --------------------------------------------------------------------------
2428   // Dimensions (Measurements) preferences
2429   // --------------------------------------------------------------------------
2430
2431   int aDimGroupId = addPreference( tr( "PREF_DIMENSIONS" ), tabId );
2432   setPreferenceProperty( aDimGroupId, "columns", 2 );
2433
2434   addPreference( tr( "PREF_DIMENSIONS_COLOR" ), aDimGroupId,
2435                  LightApp_Preferences::Color, "Geometry", "dimensions_color" );
2436
2437   int aDimLineWidthId = addPreference( tr( "PREF_DIMENSIONS_LINE_WIDTH" ), aDimGroupId, 
2438                                        LightApp_Preferences::IntSpin, "Geometry", "dimensions_line_width" );
2439
2440   setPreferenceProperty( aDimLineWidthId, "min", 1 );
2441   setPreferenceProperty( aDimLineWidthId, "max", 5 );
2442
2443   int aDimFontId = addPreference( tr( "PREF_DIMENSIONS_FONT" ), aDimGroupId, LightApp_Preferences::Font, "Geometry", "dimensions_font" );
2444
2445   int f = QtxFontEdit::Family | QtxFontEdit::Size;
2446   setPreferenceProperty( aDimFontId, "features", f );
2447   setPreferenceProperty( aDimFontId, "mode", QtxFontEdit::Custom );
2448
2449   Handle(Font_FontMgr) fmgr = Font_FontMgr::GetInstance();
2450   QString aFontFile = "";
2451   resMgr->value("resources", "GEOM", aFontFile);
2452   aFontFile = aFontFile + QDir::separator() + "Y14.5M-2009.ttf";
2453   // add enginier font into combobox
2454   /*int fontID =*/ QFontDatabase::addApplicationFont( aFontFile );
2455   Handle(Font_SystemFont) sf = new Font_SystemFont( 
2456     new TCollection_HAsciiString("Y14.5M-2009"), 
2457     Font_FA_Regular, 
2458     new TCollection_HAsciiString(aFontFile.toLatin1().data()) );
2459   // register font in OCC font manager
2460   fmgr->RegisterFont( sf, Standard_False );
2461
2462   // get list of supported fonts by OCC
2463   QStringList anOCCFonts;
2464   TColStd_SequenceOfHAsciiString theFontsNames;
2465   fmgr->GetAvailableFontsNames( theFontsNames );
2466   for(Standard_Integer i=1; i<=theFontsNames.Length(); i++) {
2467     Handle(TCollection_HAsciiString) str = theFontsNames(i);
2468     anOCCFonts << str->ToCString();
2469   }
2470   anOCCFonts.removeDuplicates();
2471   // set the supported fonts into combobox to use its only
2472   setPreferenceProperty( aDimFontId, "fonts", anOCCFonts );
2473
2474   int aDimArrLengthId = addPreference( tr( "PREF_DIMENSIONS_ARROW_LENGTH" ), aDimGroupId,
2475                                        LightApp_Preferences::DblSpin, "Geometry", "dimensions_arrow_length" );
2476
2477   setPreferenceProperty( aDimArrLengthId, "min", 1e-9 );
2478   setPreferenceProperty( aDimArrLengthId, "max", 1e+9 );
2479   setPreferenceProperty( aDimArrLengthId, "precision", 9 );
2480
2481   int aLengthUnitsId = addPreference( tr( "PREF_DIMENSIONS_LENGTH_UNITS" ), aDimGroupId,
2482                                       LightApp_Preferences::Selector, "Geometry", "dimensions_length_units" );
2483
2484   int anAngUnitsId = addPreference( tr( "PREF_DIMENSIONS_ANGLE_UNITS" ), aDimGroupId,
2485                                    LightApp_Preferences::Selector, "Geometry", "dimensions_angle_units" );
2486
2487   QStringList aListOfLengthUnits;
2488   aListOfLengthUnits << "m";
2489   aListOfLengthUnits << "cm";
2490   aListOfLengthUnits << "mm";
2491   aListOfLengthUnits << "in.";
2492   aListOfLengthUnits << "ft.";
2493
2494   QStringList aListOfAngUnits;
2495   aListOfAngUnits << "rad";
2496   aListOfAngUnits << "deg";
2497
2498   setPreferenceProperty( aLengthUnitsId, "strings", aListOfLengthUnits );
2499   setPreferenceProperty( anAngUnitsId,   "strings", aListOfAngUnits );
2500
2501   addPreference( tr( "PREF_DIMENSIONS_SHOW_UNITS" ), aDimGroupId,
2502                  LightApp_Preferences::Bool, "Geometry", "dimensions_show_units" );
2503
2504   int aDimDefFlyout = addPreference( tr( "PREF_DIMENSIONS_DEFAULT_FLYOUT" ), aDimGroupId,
2505                                      LightApp_Preferences::DblSpin, "Geometry", "dimensions_default_flyout" );
2506
2507   setPreferenceProperty( aDimDefFlyout, "min", 1e-9 );
2508   setPreferenceProperty( aDimDefFlyout, "max", 1e+9 );
2509   setPreferenceProperty( aDimDefFlyout, "precision", 9 );
2510
2511   addPreference( tr( "PREF_DIMENSIONS_USE_TEXT3D" ), aDimGroupId,
2512                  LightApp_Preferences::Bool, "Geometry", "dimensions_use_text3d" );
2513
2514   // --------------------------------------------------------------------------
2515   // Shape annotation preferences
2516   // --------------------------------------------------------------------------
2517
2518   const int aShapeAnnGroupId = addPreference( tr( "PREF_SHAPE_ANNOTATIONS" ), tabId );
2519   setPreferenceProperty( aShapeAnnGroupId, "columns", 2 );
2520
2521   addPreference( tr( "PREF_SHAPE_ANNOTATIONS_FONT_COLOR" ), aShapeAnnGroupId, LightApp_Preferences::Color, "Geometry", "shape_annotation_font_color" );
2522   addPreference( tr( "PREF_SHAPE_ANNOTATIONS_LINE_COLOR" ), aShapeAnnGroupId, LightApp_Preferences::Color, "Geometry", "shape_annotation_line_color" );
2523   const int aShapeAnnFont = 
2524     addPreference( tr( "PREF_SHAPE_ANNOTATIONS_FONT" ), aShapeAnnGroupId, LightApp_Preferences::Font, "Geometry", "shape_annotation_font" );
2525
2526   int aShapeAnnFontFeatures = QtxFontEdit::Family | QtxFontEdit::Size | QtxFontEdit::Bold | QtxFontEdit::Italic;
2527   setPreferenceProperty( aShapeAnnFont, "features", aShapeAnnFontFeatures );
2528   setPreferenceProperty( aShapeAnnFont, "mode", QtxFontEdit::Custom );
2529   setPreferenceProperty( aShapeAnnFont, "fonts", anOCCFonts );
2530
2531   const int aShapeAnnLineWidth = 
2532     addPreference( tr( "PREF_SHAPE_ANNOTATIONS_LINE_WIDTH" ), aShapeAnnGroupId, LightApp_Preferences::IntSpin, "Geometry", "shape_annotation_line_width" );
2533
2534   setPreferenceProperty( aShapeAnnLineWidth, "min", 1 );
2535   setPreferenceProperty( aShapeAnnLineWidth, "max", 5 );
2536
2537   addPreference( tr( "PREF_SHAPE_ANNOTATIONS_AUTOHIDE" ), aShapeAnnGroupId, LightApp_Preferences::Bool, "Geometry", "shape_annotation_autohide" );
2538
2539   const int aShapeAnnLineStyle =
2540     addPreference( tr( "PREF_SHAPE_ANNOTATIONS_LINE_STYLE" ), aShapeAnnGroupId, LightApp_Preferences::Selector, "Geometry", "shape_annotation_line_style" );
2541
2542   QStringList aLineStyleList;
2543   aLineStyleList.append( tr("PREF_SHAPE_ANNOTATIONS_LINESTYLE_SOLID") );
2544   aLineStyleList.append( tr("PREF_SHAPE_ANNOTATIONS_LINESTYLE_DASH") );
2545   aLineStyleList.append( tr("PREF_SHAPE_ANNOTATIONS_LINESTYLE_DOT") );
2546   aLineStyleList.append( tr("PREF_SHAPE_ANNOTATIONS_LINESTYLE_DOTDASH") );
2547
2548   QList<QVariant> aLineStyleIds;
2549   aLineStyleIds.append(0);
2550   aLineStyleIds.append(1);
2551   aLineStyleIds.append(2);
2552   aLineStyleIds.append(3);
2553
2554   setPreferenceProperty( aShapeAnnLineStyle, "strings", aLineStyleList );
2555   setPreferenceProperty( aShapeAnnLineStyle, "indexes", aLineStyleIds );
2556
2557   // --------------------------------------------------------------------------
2558   // Isoline drawing preferences
2559   // --------------------------------------------------------------------------
2560
2561   int isoGroup = addPreference( tr( "PREF_ISOS" ), tabId );
2562   setPreferenceProperty( isoGroup, "columns", 2 );
2563   int isoU = addPreference( tr( "PREF_ISOS_U" ), isoGroup,
2564                             LightApp_Preferences::IntSpin, "Geometry", "iso_number_u" );
2565   setPreferenceProperty( isoU, "min", 0 );
2566   setPreferenceProperty( isoU, "max", 100000 );
2567   int isoV = addPreference( tr( "PREF_ISOS_V" ), isoGroup,
2568                             LightApp_Preferences::IntSpin, "Geometry", "iso_number_v" );
2569   setPreferenceProperty( isoV, "min", 0 );
2570   setPreferenceProperty( isoV, "max", 100000 );
2571
2572   // Quantities with individual precision settings
2573   int precGroup = addPreference( tr( "GEOM_PREF_GROUP_PRECISION" ), tabId );
2574   setPreferenceProperty( precGroup, "columns", 2 );
2575
2576   const int nbQuantities = 8;
2577   int prec[nbQuantities], ii = 0;
2578   prec[ii++] = addPreference( tr( "GEOM_PREF_length_precision" ), precGroup,
2579                               LightApp_Preferences::IntSpin, "Geometry", "length_precision" );
2580   prec[ii++] = addPreference( tr( "GEOM_PREF_angle_precision" ), precGroup,
2581                               LightApp_Preferences::IntSpin, "Geometry", "angle_precision" );
2582   prec[ii++] = addPreference( tr( "GEOM_PREF_len_tol_precision" ), precGroup,
2583                               LightApp_Preferences::IntSpin, "Geometry", "len_tol_precision" );
2584   prec[ii++] = addPreference( tr( "GEOM_PREF_ang_tol_precision" ), precGroup,
2585                               LightApp_Preferences::IntSpin, "Geometry", "ang_tol_precision" );
2586   prec[ii++] = addPreference( tr( "GEOM_PREF_weight_precision" ), precGroup,
2587                               LightApp_Preferences::IntSpin, "Geometry", "weight_precision" );
2588   prec[ii++] = addPreference( tr( "GEOM_PREF_density_precision" ), precGroup,
2589                               LightApp_Preferences::IntSpin, "Geometry", "density_precision" );
2590   prec[ii++] = addPreference( tr( "GEOM_PREF_parametric_precision" ), precGroup,
2591                               LightApp_Preferences::IntSpin, "Geometry", "parametric_precision" );
2592   prec[ii  ] = addPreference( tr( "GEOM_PREF_param_tol_precision" ), precGroup,
2593                               LightApp_Preferences::IntSpin, "Geometry", "param_tol_precision" );
2594
2595   // Set property for precision value for spinboxes
2596   for ( ii = 0; ii < nbQuantities; ii++ ){
2597     setPreferenceProperty( prec[ii], "min", -14 );
2598     setPreferenceProperty( prec[ii], "max", 14 );
2599     setPreferenceProperty( prec[ii], "precision", 2 );
2600   }
2601
2602   int VertexGroup = addPreference( tr( "PREF_GROUP_VERTEX" ), tabId );
2603   setPreferenceProperty( VertexGroup, "columns", 2 );
2604
2605   int typeOfMarker = addPreference( tr( "PREF_TYPE_OF_MARKER" ), VertexGroup,
2606                                     LightApp_Preferences::Selector, "Geometry", "type_of_marker" );
2607
2608   int markerScale = addPreference( tr( "PREF_MARKER_SCALE" ), VertexGroup,
2609                                    LightApp_Preferences::Selector, "Geometry", "marker_scale" );
2610
2611   // Set property for default display mode
2612   QStringList aModesList;
2613   aModesList.append( tr("MEN_WIREFRAME") );
2614   aModesList.append( tr("MEN_SHADING") );
2615   aModesList.append( tr("MEN_SHADING_WITH_EDGES") );
2616   aModesList.append( tr("MEN_TEXTURE") );
2617
2618   QList<QVariant> anIndexesList;
2619   anIndexesList.append(0);
2620   anIndexesList.append(1);
2621   anIndexesList.append(2);
2622   anIndexesList.append(3);
2623
2624   setPreferenceProperty( dispmode, "strings", aModesList );
2625   setPreferenceProperty( dispmode, "indexes", anIndexesList );
2626
2627   // Set property for top level display mode
2628   QStringList aTopModesList;
2629   aTopModesList.append( tr("MEN_SHOW_ADD_WACTOR") );
2630   aTopModesList.append( tr("MEN_KEEP_CURRENT_DM") );
2631   aTopModesList.append( tr("MEN_WIREFRAME") );
2632   aTopModesList.append( tr("MEN_SHADING") );
2633   aTopModesList.append( tr("MEN_SHADING_WITH_EDGES") );
2634
2635   QList<QVariant> aTopIndexesList;
2636   aTopIndexesList.append(0);
2637   aTopIndexesList.append(1);
2638   aTopIndexesList.append(2);
2639   aTopIndexesList.append(3);
2640   aTopIndexesList.append(4);
2641
2642   setPreferenceProperty( top_lev_dm, "strings", aTopModesList );
2643   setPreferenceProperty( top_lev_dm, "indexes", aTopIndexesList );
2644
2645   // Set property for step value for spinboxes
2646   setPreferenceProperty( step, "min", 1 );
2647   setPreferenceProperty( step, "max", 10000 );
2648   setPreferenceProperty( step, "precision", 3 );
2649
2650   // Set property for trandparency value for spinboxes
2651   setPreferenceProperty( transparency, "min", 0 );
2652   setPreferenceProperty( transparency, "max", 100 );
2653
2654   // Set property for deflection value for spinboxes
2655   setPreferenceProperty( defl, "min", GEOM::minDeflection() );
2656   setPreferenceProperty( defl, "max", 1.0 );
2657   setPreferenceProperty( defl, "step", 1.0e-04 );
2658   setPreferenceProperty( defl, "precision", 6 );
2659
2660   // Set property for default material
2661   setPreferenceProperty( material, "strings", Material_ResourceMgr::resourceMgr()->materials() );
2662
2663   // Set property vertex marker type
2664   QList<QVariant> aMarkerTypeIndicesList;
2665   QList<QVariant> aMarkerTypeIconsList;
2666
2667   for ( int i = GEOM::MT_POINT; i < GEOM::MT_USER; i++ ) {
2668     QString icoFile = QString( "ICON_VERTEX_MARKER_%1" ).arg( i );
2669     QPixmap pixmap = resMgr->loadPixmap( "GEOM", tr( qPrintable( icoFile ) ) );
2670     aMarkerTypeIndicesList << (i-1);
2671     aMarkerTypeIconsList << pixmap;
2672   }
2673
2674   setPreferenceProperty( typeOfMarker, "indexes", aMarkerTypeIndicesList );
2675   setPreferenceProperty( typeOfMarker, "icons",   aMarkerTypeIconsList );
2676
2677   // Set property for vertex marker scale
2678   QList<QVariant> aMarkerScaleIndicesList;
2679   QStringList     aMarkerScaleValuesList;
2680
2681   for ( int iii = GEOM::MS_10; iii <= GEOM::MS_70; iii++ ) {
2682     aMarkerScaleIndicesList << iii;
2683     aMarkerScaleValuesList  << QString::number( (iii-(int)GEOM::MS_10)*0.5 + 1.0 );
2684   }
2685
2686   setPreferenceProperty( markerScale, "strings", aMarkerScaleValuesList );
2687   setPreferenceProperty( markerScale, "indexes", aMarkerScaleIndicesList );
2688
2689   // Scalar bar for field step presentation
2690   int scalarBarGroup = addPreference( tr( "PREF_GROUP_SCALAR_BAR" ), tabId );
2691   setPreferenceProperty( scalarBarGroup, "columns", 2 );
2692
2693   int sbXPosition = addPreference( tr( "PREF_SCALAR_BAR_X_POSITION" ), scalarBarGroup,
2694                                    LightApp_Preferences::DblSpin, "Geometry", "scalar_bar_x_position" );
2695   setPreferenceProperty( sbXPosition, "min", 0 );
2696   setPreferenceProperty( sbXPosition, "max", 1 );
2697   setPreferenceProperty( sbXPosition, "step", 0.05 );
2698
2699   int sbYPosition = addPreference( tr( "PREF_SCALAR_BAR_Y_POSITION" ), scalarBarGroup,
2700                                    LightApp_Preferences::DblSpin, "Geometry", "scalar_bar_y_position" );
2701   setPreferenceProperty( sbYPosition, "min", 0 );
2702   setPreferenceProperty( sbYPosition, "max", 1 );
2703   setPreferenceProperty( sbYPosition, "step", 0.05 );
2704
2705   int sbWidth = addPreference( tr( "PREF_SCALAR_BAR_WIDTH" ), scalarBarGroup,
2706                                LightApp_Preferences::DblSpin, "Geometry", "scalar_bar_width" );
2707   setPreferenceProperty( sbWidth, "min", 0 );
2708   setPreferenceProperty( sbWidth, "max", 1 );
2709   setPreferenceProperty( sbWidth, "step", 0.05 );
2710
2711   int sbHeight = addPreference( tr( "PREF_SCALAR_BAR_HEIGHT" ), scalarBarGroup,
2712                                 LightApp_Preferences::DblSpin, "Geometry", "scalar_bar_height" );
2713   setPreferenceProperty( sbHeight, "min", 0 );
2714   setPreferenceProperty( sbHeight, "max", 1 );
2715   setPreferenceProperty( sbHeight, "step", 0.05 );
2716
2717   int sbTextHeight = addPreference( tr( "PREF_SCALAR_BAR_TEXT_HEIGHT" ), scalarBarGroup,
2718                                     LightApp_Preferences::IntSpin, "Geometry", "scalar_bar_text_height" );
2719   setPreferenceProperty( sbTextHeight, "min", 6 );
2720   setPreferenceProperty( sbTextHeight, "max", 24 );
2721   setPreferenceProperty( sbTextHeight, "step", 1 );
2722
2723   int sbNbIntervals = addPreference( tr( "PREF_SCALAR_BAR_NUMBER_OF_INTERVALS" ), scalarBarGroup,
2724                                      LightApp_Preferences::IntSpin, "Geometry", "scalar_bar_nb_intervals" );
2725   setPreferenceProperty( sbNbIntervals, "min", 2 );
2726   setPreferenceProperty( sbNbIntervals, "max", 64 );
2727   setPreferenceProperty( sbNbIntervals, "step", 1 );
2728
2729   int originGroup = addPreference( tr( "PREF_GROUP_ORIGIN_AND_BASE_VECTORS" ), tabId );
2730   setPreferenceProperty( originGroup, "columns", 2 );
2731
2732   int baseVectorsLength = addPreference( tr( "PREF_BASE_VECTORS_LENGTH" ), originGroup,
2733                                          LightApp_Preferences::DblSpin, "Geometry", "base_vectors_length" );
2734   setPreferenceProperty( baseVectorsLength, "min", 0.01 );
2735   setPreferenceProperty( baseVectorsLength, "max", 1000 );
2736
2737   addPreference( tr( "PREF_AUTO_CREATE" ), originGroup,
2738                  LightApp_Preferences::Bool, "Geometry", "auto_create_base_objects" );
2739
2740   int operationsGroup = addPreference( tr( "PREF_GROUP_OPERATIONS" ), tabId );
2741   setPreferenceProperty( operationsGroup, "columns", 2 );
2742
2743   addPreference( tr( "GEOM_PREVIEW" ), operationsGroup,
2744                  LightApp_Preferences::Bool, "Geometry", "geom_preview" );
2745
2746   addPreference( tr( "PREF_HIDE_INPUT_OBJECT" ), operationsGroup,
2747                  LightApp_Preferences::Bool, "Geometry", "hide_input_object" );
2748
2749   int DependencyViewId = addPreference( tr( "PREF_TAB_DEPENDENCY_VIEW" ) );
2750
2751   int treeGeneralGroup = addPreference( tr( "PREF_GROUP_GENERAL" ), DependencyViewId );
2752
2753   int hierarchy_type = addPreference( tr( "PREF_HIERARCHY_TYPE" ), treeGeneralGroup,
2754                       LightApp_Preferences::Selector, "Geometry", "dependency_tree_hierarchy_type" );
2755
2756   QStringList aHierarchyTypeList;
2757   aHierarchyTypeList.append( tr("MEN_BOTH_ASCENDANTS_DESCENDANTS") );
2758   aHierarchyTypeList.append( tr("MEN_ONLY_ASCENDANTS") );
2759   aHierarchyTypeList.append( tr("MEN_ONLY_DESCENDANTS") );
2760
2761   QList<QVariant> aHierarchyTypeIndexesList;
2762   aHierarchyTypeIndexesList.append(0);
2763   aHierarchyTypeIndexesList.append(1);
2764   aHierarchyTypeIndexesList.append(2);
2765
2766   setPreferenceProperty( hierarchy_type, "strings", aHierarchyTypeList );
2767   setPreferenceProperty( hierarchy_type, "indexes", aHierarchyTypeIndexesList );
2768
2769   addPreference( tr( "GEOM_MOVE_POSSIBILITY" ), treeGeneralGroup,
2770                  LightApp_Preferences::Bool, "Geometry", "dependency_tree_move_nodes" );
2771
2772   int treeColorGroup = addPreference( tr( "PREF_GROUP_DEPENDENCY_VIEW_COLOR" ), DependencyViewId );
2773
2774   addPreference( tr( "PREF_DEPENDENCY_VIEW_BACKGROUND_COLOR"), treeColorGroup,
2775                  LightApp_Preferences::Color, "Geometry", "dependency_tree_background_color" );
2776
2777   addPreference( tr( "PREF_DEPENDENCY_VIEW_NODE_COLOR"), treeColorGroup,
2778                  LightApp_Preferences::Color, "Geometry", "dependency_tree_node_color" );
2779   addPreference( tr( "PREF_DEPENDENCY_VIEW_MAIN_NODE_COLOR"), treeColorGroup,
2780                  LightApp_Preferences::Color, "Geometry", "dependency_tree_main_node_color" );
2781   addPreference( tr( "PREF_DEPENDENCY_VIEW_UNPUBLISH_NODE_COLOR"), treeColorGroup,
2782                  LightApp_Preferences::Color, "Geometry", "dependency_tree_unpublish_node_color" );
2783   addPreference( tr( "PREF_DEPENDENCY_VIEW_SELECT_NODE_COLOR"), treeColorGroup,
2784                  LightApp_Preferences::Color, "Geometry", "dependency_tree_select_node_color" );
2785
2786   addPreference( tr( "PREF_DEPENDENCY_VIEW_ARROW_COLOR"), treeColorGroup,
2787                  LightApp_Preferences::Color, "Geometry", "dependency_tree_arrow_color" );
2788   addPreference( tr( "PREF_DEPENDENCY_VIEW_HIGHLIGHT_ARROW_COLOR"), treeColorGroup,
2789                  LightApp_Preferences::Color, "Geometry", "dependency_tree_highlight_arrow_color" );
2790   addPreference( tr( "PREF_DEPENDENCY_VIEW_SELECT_ARROW_COLOR"), treeColorGroup,
2791                  LightApp_Preferences::Color, "Geometry", "dependency_tree_select_arrow_color" );
2792
2793
2794
2795
2796 }
2797
2798 void GeometryGUI::preferencesChanged( const QString& section, const QString& param )
2799 {
2800   if (section == "Geometry") {
2801     SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
2802     if (param == QString("SettingsGeomStep")) {
2803       double spin_step = aResourceMgr->doubleValue(section, param, 100.);
2804       EmitSignalDefaultStepValueChanged(spin_step);
2805     }
2806     else if (param == QString("toplevel_color")) {
2807       QColor c = aResourceMgr->colorValue( "Geometry", "toplevel_color", QColor( 170, 85, 0 ) );
2808       GEOM_AISShape::setTopLevelColor(SalomeApp_Tools::color(c));
2809     }
2810     else if (param == QString("toplevel_dm")) {
2811       GEOM_AISShape::setTopLevelDisplayMode((GEOM_AISShape::TopLevelDispMode)aResourceMgr->integerValue("Geometry", "toplevel_dm", 0));
2812     }
2813     else if (param == QString("scalar_bar_x_position") ||
2814              param == QString("scalar_bar_y_position") ||
2815              param == QString("scalar_bar_width") ||
2816              param == QString("scalar_bar_height") ||
2817              param == QString("scalar_bar_text_height") ||
2818              param == QString("scalar_bar_nb_intervals")) {
2819       if( SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) )
2820       {
2821         GEOM_Displayer aDisplayer( aStudy );
2822         bool anIsRedisplayFieldSteps = param == QString("scalar_bar_nb_intervals");
2823         aDisplayer.UpdateColorScale( anIsRedisplayFieldSteps, true );
2824       }
2825     }
2826     else if ( param == QString("dimensions_color")            ||
2827               param == QString("dimensions_line_width")       ||
2828               param == QString("dimensions_font")             ||
2829               param == QString("dimensions_arrow_length")     ||
2830               param == QString("dimensions_show_units")       ||
2831               param == QString("dimensions_length_units")     ||
2832               param == QString("dimensions_angle_units")      ||
2833               param == QString("dimensions_use_text3d")       ||
2834               param == QString("shape_annotation_font_color") ||
2835               param == QString("shape_annotation_line_color") ||
2836               param == QString("shape_annotation_font")       ||
2837               param == QString("shape_annotation_line_width") ||
2838               param == QString("shape_annotation_autohide")   ||
2839               param == QString("shape_annotation_line_style") ||
2840               param == QString("shape_annotation_line_style") ||
2841               param == QString("label_color") )
2842     {
2843       SalomeApp_Application* anApp = getApp();
2844       if ( !anApp )
2845       {
2846         return;
2847       }
2848
2849       SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( anApp->activeStudy() );
2850       if ( !aStudy )
2851       {
2852         return;
2853       }
2854
2855       GEOM_Displayer aDisplayer( aStudy );
2856
2857       ViewManagerList aVMs;
2858       anApp->viewManagers( OCCViewer_Viewer::Type(), aVMs );
2859       ViewManagerList::Iterator anIt = aVMs.begin();
2860       for ( ; anIt != aVMs.end(); ++anIt )
2861       {
2862         SOCC_Viewer* aViewer = dynamic_cast<SOCC_Viewer*>( (*anIt)->getViewModel() );
2863         if ( !aViewer )
2864         {
2865           continue;
2866         }
2867
2868         SALOME_ListIO aVisible;
2869         aViewer->GetVisible( aVisible );
2870
2871         GEOMGUI_AnnotationMgr* anAnnotationMgr = GetAnnotationMgr();
2872         if ( anAnnotationMgr ) {
2873           SALOME_ListIteratorOfListIO anIter( aVisible );
2874           while ( anIter.More() ) {
2875             if ( anAnnotationMgr->isAnnotationEntry( anIter.Value()->getEntry() ) ) {
2876               aVisible.Remove( anIter );
2877             }
2878             else {
2879               anIter.Next();
2880             }
2881           }
2882         }
2883
2884         aDisplayer.Redisplay( aVisible, false, aViewer );
2885       }
2886       if ( param == QString( "label_color" ) ) {
2887         ViewManagerList aVMsVTK;
2888         anApp->viewManagers( SVTK_Viewer::Type(), aVMsVTK );
2889         ViewManagerList::Iterator anIt = aVMsVTK.begin();
2890         for ( ; anIt != aVMsVTK.end(); ++anIt )
2891         {
2892             SVTK_Viewer* aViewer = dynamic_cast<SVTK_Viewer*>( (*anIt)->getViewModel() );
2893             if ( !aViewer )
2894             {
2895               continue;
2896             }
2897             SALOME_ListIO aVisible;
2898             aViewer->GetVisible( aVisible );
2899             aDisplayer.Redisplay( aVisible, false, aViewer );
2900           }
2901       }
2902       aDisplayer.UpdateViewer();
2903     }
2904     else if ( param.startsWith( "dependency_tree") )
2905       emit SignalDependencyTreeParamChanged( section, param );
2906   }
2907 }
2908
2909 LightApp_Displayer* GeometryGUI::displayer()
2910 {
2911   if ( !myDisplayer )
2912     myDisplayer = new GEOM_Displayer( dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) );
2913   return myDisplayer;
2914 }
2915
2916 void GeometryGUI::setLocalSelectionMode(const int mode)
2917 {
2918   myLocalSelectionMode = mode;
2919 }
2920
2921 int GeometryGUI::getLocalSelectionMode() const
2922 {
2923   return myLocalSelectionMode;
2924 }
2925
2926 const char gSeparator = '_'; // character used to separate parameter names
2927 const char gDigitsSep = ':'; // character used to separate numeric parameter values (color = r:g:b)
2928
2929 /*!
2930  * \brief Store visual parameters
2931  *
2932  * This method is called just before the study document is saved.
2933  * Store visual parameters in AttributeParameter attribute(s)
2934  */
2935 void GeometryGUI::storeVisualParameters (int savePoint)
2936 {
2937   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
2938   if ( !appStudy || !appStudy->studyDS() )
2939     return;
2940
2941   _PTR(Study) studyDS = appStudy->studyDS();
2942
2943   // componentName is used for encoding of entries when storing them in IParameters
2944   std::string componentName = myComponentGeom->ComponentDataType();
2945   //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
2946   //if (!aSComponent) return;
2947
2948   // IParameters
2949   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
2950                                                              componentName.c_str(),
2951                                                              savePoint);
2952   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
2953
2954   QSet<QString> anEntriesToStoreShared;
2955   QList<SUIT_ViewManager*> lst;
2956   QList<SUIT_ViewManager*>::Iterator it;
2957
2958   GEOMGUI_AnnotationMgr* aAnnotationMgr = GetAnnotationMgr();
2959
2960   // main cycle to store parameters of displayed objects
2961   lst.clear();
2962   getApp()->viewManagers(lst);
2963   for (it = lst.begin(); it != lst.end(); it++) {
2964     SUIT_ViewManager* vman = *it;
2965     QString vType = vman->getType();
2966     SUIT_ViewModel* vmodel = vman->getViewModel();
2967     SALOME_View* aView = dynamic_cast<SALOME_View*>(vmodel);
2968
2969     int aMgrId = vman->getGlobalId();
2970     // saving VTK actors properties
2971     QVector<SUIT_ViewWindow*> views = vman->getViews();
2972     for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++) {
2973       const ObjMap& anObjects = appStudy->getObjectProperties(aMgrId);
2974       ObjMap::ConstIterator o_it = anObjects.begin();
2975       for (; o_it != anObjects.end(); o_it++) {
2976         const PropMap& aProps = o_it.value();
2977
2978         //Check that object exists in the study
2979         _PTR(SObject) obj( studyDS->FindObjectID( o_it.key().toLatin1().data() ) );
2980         if ( !obj || !(aProps.count() > 0))
2981           continue;
2982         // entry is "encoded" = it does NOT contain component adress, since it is a
2983         // subject to change on next component loading
2984
2985         std::string entry = ip->encodeEntry(o_it.key().toLatin1().data(), componentName);
2986
2987         _PTR(GenericAttribute) anAttr;
2988         if (!obj->FindAttribute(anAttr, "AttributeIOR"))
2989           continue;
2990
2991         // remember entry of object to store shared GEOM properties
2992         // (e.g. dimension properties).
2993         if ( vType == OCCViewer_Viewer::Type() )
2994         {
2995           anEntriesToStoreShared.insert( o_it.key() );
2996         }
2997
2998         QString param, occParam = vType;
2999         occParam += GEOM::sectionSeparator();
3000         occParam += QString::number(aMgrId);
3001         occParam += GEOM::sectionSeparator();
3002
3003         if (aProps.contains(GEOM::propertyName( GEOM::Visibility ))) {
3004           param = occParam + GEOM::propertyName( GEOM::Visibility );
3005           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::Visibility )).toBool() ? "On" : "Off");
3006         }
3007
3008         if (aProps.contains(GEOM::propertyName( GEOM::DisplayMode ))) {
3009           param = occParam + GEOM::propertyName( GEOM::DisplayMode );
3010           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::DisplayMode )).toString().toStdString());
3011         }
3012
3013         if (aProps.contains(GEOM::propertyName( GEOM::Color ))) {
3014           QColor c = aProps.value(GEOM::propertyName( GEOM::Color )).value<QColor>();
3015           QStringList val;
3016           val << QString::number(c.redF());
3017           val << QString::number(c.greenF());
3018           val << QString::number(c.blueF());
3019           param = occParam + GEOM::propertyName( GEOM::Color );
3020           ip->setParameter(entry, param.toStdString(), val.join( GEOM::subSectionSeparator()).toStdString());
3021         }
3022         
3023         if (aProps.contains(GEOM::propertyName( GEOM::Texture ))) {
3024           param = occParam + GEOM::propertyName( GEOM::Texture );
3025           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::Texture )).toString().toStdString());
3026         }
3027
3028         if (vType == SVTK_Viewer::Type()) {
3029           if (aProps.contains(GEOM::propertyName( GEOM::Opacity ))) {
3030             param = occParam + GEOM::propertyName( GEOM::Opacity );
3031             ip->setParameter(entry, param.toStdString(), QString::number(1. - aProps.value(GEOM::propertyName( GEOM::Transparency )).toDouble()).toStdString());
3032           }
3033         } else if (vType == SOCC_Viewer::Type()) {
3034           if (aProps.contains(GEOM::propertyName( GEOM::Transparency ))) {
3035             param = occParam + GEOM::propertyName( GEOM::Transparency );
3036             ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::Transparency )).toString().toStdString());
3037           }
3038
3039           if (aProps.contains(GEOM::propertyName( GEOM::TopLevel ))) {
3040             param = occParam + GEOM::propertyName( GEOM::TopLevel );
3041             ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::TopLevel )).toString().toStdString());
3042           }
3043         }
3044
3045         if (aProps.contains(GEOM::propertyName( GEOM::NbIsos ))) {
3046           param = occParam + GEOM::propertyName( GEOM::NbIsos );
3047           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::NbIsos )).toString().toStdString());
3048         }
3049
3050         if (aProps.contains(GEOM::propertyName( GEOM::EdgesDirection ))) {
3051           param = occParam + GEOM::propertyName( GEOM::EdgesDirection );
3052           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::EdgesDirection )).toString().toStdString());
3053         }
3054
3055         if (aProps.contains(GEOM::propertyName( GEOM::Vertices ))) {
3056           param = occParam + GEOM::propertyName( GEOM::Vertices );
3057           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::Vertices )).toString().toStdString());
3058         }
3059
3060         if (aProps.contains(GEOM::propertyName( GEOM::ShowName ))) {
3061           param = occParam + GEOM::propertyName( GEOM::ShowName );
3062           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::ShowName )).toString().toStdString());
3063         }
3064
3065         if (aProps.contains(GEOM::propertyName( GEOM::Deflection ))) {
3066           param = occParam + GEOM::propertyName( GEOM::Deflection );
3067           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::Deflection )).toString().toStdString());
3068         }
3069
3070         //Marker type of the vertex - ONLY for the "Vertex" and "Compound of the Vertex"
3071         if (aProps.contains(GEOM::propertyName( GEOM::PointMarker ))) {
3072           param = occParam + GEOM::propertyName( GEOM::PointMarker );
3073           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::PointMarker )).toString().toStdString());
3074         }
3075
3076         if (aProps.contains(GEOM::propertyName( GEOM::Material ))) {
3077           param = occParam + GEOM::propertyName( GEOM::Material );
3078           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::Material )).toString().toStdString());
3079         }
3080
3081         if (aProps.contains(GEOM::propertyName( GEOM::LineWidth ))) {
3082              param = occParam + GEOM::propertyName( GEOM::LineWidth );
3083            ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::LineWidth )).toString().toStdString());
3084         }
3085
3086         if (aProps.contains(GEOM::propertyName( GEOM::IsosWidth ))) {
3087           param = occParam + GEOM::propertyName( GEOM::IsosWidth );
3088           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::IsosWidth )).toString().toStdString());
3089         }
3090
3091         if ( vType == SOCC_Viewer::Type() && aAnnotationMgr ) {
3092           std::string anAnnotationInfo = GetAnnotationMgr()->getDisplayedIndicesInfo(
3093                                             o_it.key().toLatin1().data(), dynamic_cast<SOCC_Viewer*>(aView) ).toStdString();
3094           if (!anAnnotationInfo.empty()) {
3095             param = occParam + "ShapeAnnotationVisibleItems";
3096             ip->setParameter(entry, param.toStdString(), anAnnotationInfo);
3097           }
3098         }
3099       } // object iterator
3100     } // for (views)
3101   } // for (viewManagers)
3102
3103   // store shape annotation and dimension attributes of objects:
3104   // since the displayed object always persists in property map, we remember the object entries
3105   // on the passes when we store viewer related properties - to avoid extra iterations on GEOM component tree.
3106   const QString aDimensionParam = OCCViewer_Viewer::Type() + GEOM::sectionSeparator() + GEOM::propertyName( GEOM::Dimensions );
3107   const QString aAnnotationParam = OCCViewer_Viewer::Type() + GEOM::sectionSeparator() + GEOM::propertyName( GEOM::ShapeAnnotations );
3108   QSet<QString>::ConstIterator aEntryIt = anEntriesToStoreShared.constBegin();
3109   for ( ; aEntryIt != anEntriesToStoreShared.constEnd(); ++aEntryIt )
3110   {
3111     std::string aStudyEntry = (*aEntryIt).toLatin1().data();
3112     std::string aStoreEntry = ip->encodeEntry( aStudyEntry, componentName );
3113
3114     // store dimension parameters
3115     GEOMGUI_DimensionProperty aDimensions( appStudy, aStudyEntry );
3116     if ( aDimensions.GetNumber() != 0 ) {
3117       ip->setParameter( aStoreEntry, aDimensionParam.toStdString(), ((QString)aDimensions).toLatin1().data() );
3118     }
3119
3120     _PTR(SObject) aObj( studyDS->FindObjectID( aStudyEntry ) );
3121     const Handle(GEOMGUI_AnnotationAttrs) aShapeAnnAttr = GEOMGUI_AnnotationAttrs::FindAttributes( aObj );
3122     if ( !aShapeAnnAttr.IsNull() ) {
3123       ip->setParameter( aStoreEntry, aAnnotationParam.toStdString(), aShapeAnnAttr->ExportAsPropertyString().toLatin1().data() );
3124     }
3125   }
3126 }
3127
3128 /*!
3129  * \brief Restore visual parameters
3130  *
3131  * This method is called after the study document is opened.
3132  * Restore visual parameters from AttributeParameter attribute(s)
3133  */
3134 void GeometryGUI::restoreVisualParameters (int savePoint)
3135 {
3136   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
3137   if (!appStudy || !appStudy->studyDS())
3138     return;
3139   _PTR(Study) studyDS = appStudy->studyDS();
3140
3141   // componentName is used for encoding of entries when storing them in IParameters
3142   std::string componentName = myComponentGeom->ComponentDataType();
3143   //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
3144   //if (!aSComponent) return;
3145
3146   // IParameters
3147   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
3148                                                              componentName.c_str(),
3149                                                              savePoint);
3150   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
3151
3152   std::vector<std::string> entries = ip->getEntries();
3153
3154   for (std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt)
3155   {
3156     // entry is a normal entry - it should be "decoded" (setting base adress of component)
3157     QString entry (ip->decodeEntry(*entIt).c_str());
3158
3159     // Check that the entry corresponds to a real object in the Study
3160     // as the object may be deleted or modified after the visual state is saved.
3161     _PTR(SObject) so = studyDS->FindObjectID(entry.toLatin1().data());
3162     if (!so) continue; //Skip the not existent entry
3163
3164     std::vector<std::string> paramNames = ip->getAllParameterNames( *entIt );
3165     std::vector<std::string> paramValues = ip->getAllParameterValues( *entIt );
3166
3167     std::vector<std::string>::iterator namesIt = paramNames.begin();
3168     std::vector<std::string>::iterator valuesIt = paramValues.begin();
3169
3170     // actors are stored in a map after displaying of them for
3171     // quicker access in the future: map < viewID to actor >
3172     NCollection_DataMap<int, GEOM_Actor*          > vtkActors;
3173     NCollection_DataMap<int, Handle(GEOM_AISShape)> occActors;
3174
3175     QString viewerTypStr;
3176     QString viewIndexStr;
3177     int viewIndex;
3178     QVector<PropMap> aListOfMap;
3179
3180     for (; namesIt != paramNames.end(); ++namesIt, ++valuesIt)
3181     {
3182       // visual parameters are stored in strings as follows: 
3183       //   1) ViewerType_ViewIndex_ParamName
3184       //   2) ViewerType_ParamName (shared for GEOM module)
3185       // '_' is used as separator and should not be used in viewer type or parameter names.
3186       QStringList lst = QString((*namesIt).c_str()).split( GEOM::sectionSeparator(), QString::SkipEmptyParts);
3187
3188       bool isShared = lst.size() == 2;
3189       bool isViewer = lst.size() == 3;
3190       if ( !isShared && !isViewer )
3191       {
3192         continue;
3193       }
3194
3195       // shared visual parameters
3196       if ( isShared )
3197       {
3198         QString aParamNameStr( lst[1] );
3199         QString aValuesStr( (*valuesIt).c_str() );
3200
3201         // shared dimension properties are stored as attribute
3202         if ( aParamNameStr == GEOM::propertyName( GEOM::Dimensions ) )
3203         {
3204           GEOMGUI_DimensionProperty aDimensionProp( aValuesStr );
3205           aDimensionProp.SaveToAttribute( appStudy, entry.toLatin1().data() );
3206         }
3207         else if ( aParamNameStr == GEOM::propertyName( GEOM::ShapeAnnotations ) )
3208         {
3209           Handle(GEOMGUI_AnnotationAttrs) anAttr =
3210             GEOMGUI_AnnotationAttrs::FindOrCreateAttributes( so, appStudy );
3211
3212           anAttr->ImportFromPropertyString( aValuesStr );
3213         }
3214
3215         continue;
3216       }
3217
3218       // per view visual parameters
3219       viewerTypStr = lst[0];
3220       viewIndexStr = lst[1];
3221       QString paramNameStr = lst[2];
3222
3223       bool ok;
3224       viewIndex = viewIndexStr.toUInt(&ok);
3225       if (!ok) // bad conversion of view index to integer
3226         continue;
3227
3228       if ((viewIndex + 1) > aListOfMap.count()) {
3229         aListOfMap.resize(viewIndex + 1);
3230       }
3231
3232       QString val((*valuesIt).c_str());
3233       if (paramNameStr == GEOM::propertyName( GEOM::Visibility )) {
3234         aListOfMap[viewIndex].insert(GEOM::propertyName( GEOM::Visibility ), val == "On");
3235       } else if (paramNameStr == GEOM::propertyName( GEOM::Opacity )) {
3236         aListOfMap[viewIndex].insert(GEOM::propertyName( GEOM::Transparency ), 1. - val.toDouble());
3237       } else if (paramNameStr == GEOM::propertyName( GEOM::Transparency )) {
3238         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::Transparency ), val.toDouble() );
3239       } else if (paramNameStr == GEOM::propertyName( GEOM::TopLevel )) {
3240         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::TopLevel ), val == "true" || val == "1");
3241       } else if (paramNameStr == GEOM::propertyName( GEOM::DisplayMode )) {
3242         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::DisplayMode ), val.toInt());
3243       } else if (paramNameStr == GEOM::propertyName( GEOM::NbIsos )) {
3244         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::NbIsos ), val);
3245       } else if (paramNameStr == GEOM::propertyName( GEOM::Color )) {
3246         QStringList rgb = val.split(GEOM::subSectionSeparator());
3247         if (rgb.count() == 3) {
3248           QColor c = QColor::fromRgbF(rgb[0].toDouble(), rgb[1].toDouble(), rgb[2].toDouble());
3249           aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::Color ), c);
3250         }
3251       } else if (paramNameStr == GEOM::propertyName( GEOM::Texture )) {
3252         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::Texture ), val );
3253       } else if (paramNameStr == GEOM::propertyName( GEOM::EdgesDirection )) {
3254         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::EdgesDirection ), val == "true" || val == "1");
3255       } else if (paramNameStr == GEOM::propertyName( GEOM::Vertices )) {
3256         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::Vertices ), val == "true" || val == "1");
3257       } else if (paramNameStr == GEOM::propertyName( GEOM::ShowName )) {
3258         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::ShowName ), val == "true" || val == "1");
3259       } else if (paramNameStr == GEOM::propertyName( GEOM::Deflection )) {
3260         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::Deflection ), val.toDouble());
3261       } else if (paramNameStr == GEOM::propertyName( GEOM::PointMarker )) {
3262         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::PointMarker ), val);
3263       } else if (paramNameStr == GEOM::propertyName( GEOM::Material )) {
3264         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::Material ), val);
3265       } else if (paramNameStr == GEOM::propertyName( GEOM::LineWidth )) {
3266         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::LineWidth ), val.toInt());
3267       } else if (paramNameStr == GEOM::propertyName( GEOM::IsosWidth )) {
3268         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::IsosWidth ), val.toInt());
3269       } else if (paramNameStr == "ShapeAnnotationVisibleItems") {
3270         aListOfMap[viewIndex].insert( "ShapeAnnotationVisibleItems", val);
3271       }
3272
3273     } // for names/parameters iterator
3274
3275     QList<SUIT_ViewManager*> lst = getApp()->viewManagers();
3276
3277     for (int index = 0; index < aListOfMap.count(); index++) {
3278       appStudy->setObjectProperties(index, entry, aListOfMap[index]);
3279
3280       //Get Visibility property of the current PropMap
3281       if (aListOfMap[index].value(GEOM::propertyName( GEOM::Visibility )) == 1) {
3282         SUIT_ViewManager* vman = lst.at(index);
3283         SUIT_ViewModel* vmodel = vman->getViewModel();
3284         SALOME_View* aView = dynamic_cast<SALOME_View*>(vmodel);
3285         displayer()->Display(entry, true, aView);
3286
3287         if ( vmodel->getType() == SOCC_Viewer::Type() ) {
3288           PropMap& aProps = aListOfMap[index];
3289           if ( aProps.contains( "ShapeAnnotationVisibleItems" ) ) {
3290             SOCC_Viewer* aSOCCView = dynamic_cast<SOCC_Viewer*>( aView );
3291             GetAnnotationMgr()->setDisplayedIndicesInfo( entry, aSOCCView, aProps["ShapeAnnotationVisibleItems"].toString() );
3292           }
3293         }
3294       }
3295     }
3296   } // for entries iterator
3297
3298   // update all VTK and OCC views
3299   QList<SUIT_ViewManager*> lst;
3300   getApp()->viewManagers(lst);
3301   for (QList<SUIT_ViewManager*>::Iterator it = lst.begin(); it != lst.end(); it++) {
3302     SUIT_ViewModel* vmodel = (*it)->getViewModel();
3303     if (!vmodel)
3304       continue;
3305     if (vmodel->getType() == SVTK_Viewer::Type()) {
3306       SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) (*it)->getActiveView();
3307       vtkView->getRenderer()->ResetCameraClippingRange();
3308       vtkView->Repaint();
3309     }
3310     else if (vmodel->getType() == SOCC_Viewer::Type()) {
3311       //SOCC_ViewWindow* occView = (SOCC_ViewWindow*) (*it)->getActiveView();
3312       SALOME_View* occVMod = dynamic_cast<SALOME_View*>(vmodel);
3313       if (occVMod)
3314         occVMod->Repaint();
3315     }
3316   }
3317
3318   if ( myTextTreeWdg ) {
3319     myTextTreeWdg->updateTree();
3320   }
3321 }
3322
3323 // Compute current name mode of the viewer
3324 void UpdateNameMode( SalomeApp_Application* app )
3325 {
3326   bool isMode = false;
3327   SalomeApp_Study* aStudy = dynamic_cast< SalomeApp_Study* >( app->activeStudy() );
3328   SUIT_ViewWindow* viewWindow = app->desktop()->activeWindow();
3329   GEOM_Displayer displayer( aStudy );
3330   int aMgrId = viewWindow->getViewManager()->getGlobalId();
3331
3332   SALOME_View* window = displayer.GetActiveView();
3333   if ( !window ) return;
3334
3335   SALOME_ListIO anIOlst;
3336   window->GetVisible( anIOlst );
3337
3338   for ( SALOME_ListIteratorOfListIO It( anIOlst ); It.More(); It.Next() ) {
3339     Handle( SALOME_InteractiveObject ) io = It.Value();
3340     QVariant v = aStudy->getObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::ShowName ), QVariant() );
3341     bool isIONameMode =  v.isValid() ? v.toBool() : false;
3342     if( isIONameMode )
3343       isMode = true;
3344   }
3345   viewWindow->setProperty( "NameMode", isMode );
3346 }
3347
3348 void GeometryGUI::onViewAboutToShow()
3349 {
3350   SUIT_ViewWindow* window = application()->desktop()->activeWindow();
3351   QAction* a = action( GEOMOp::OpSwitchVectors );
3352   QAction* aVerticesAction = action( GEOMOp::OpSwitchVertices );
3353   QAction* aNameAction = action( GEOMOp::OpSwitchName );
3354   if ( window ) {
3355     a->setEnabled(true);
3356     bool vmode = window->property("VectorsMode").toBool();
3357     a->setText ( vmode == 1 ? tr( "MEN_VECTOR_MODE_OFF" ) : tr("MEN_VECTOR_MODE_ON") );
3358     aVerticesAction->setEnabled(true);
3359     vmode = window->property("VerticesMode").toBool();
3360     aVerticesAction->setText ( vmode == 1 ? tr( "MEN_VERTICES_MODE_OFF" ) : tr("MEN_VERTICES_MODE_ON") );
3361     UpdateNameMode( getApp() );
3362     aNameAction->setEnabled(true);
3363     vmode = window->property("NameMode").toBool();
3364     aNameAction->setText ( vmode == 1 ? tr( "MEN_NAME_MODE_OFF" ) : tr("MEN_NAME_MODE_ON") );
3365   } else {
3366     a->setText ( tr("MEN_VECTOR_MODE_ON") );
3367     a->setEnabled(false);
3368     aVerticesAction->setText ( tr("MEN_VERTICES_MODE_ON") );
3369     aVerticesAction->setEnabled(false);
3370     aNameAction->setText ( tr("MEN_NAME_MODE_ON") );
3371     aNameAction->setEnabled(false);
3372   }
3373 }
3374
3375 /*!
3376   \brief Return action by id
3377   \param id identifier of the action
3378   \return action
3379 */
3380 QAction* GeometryGUI::getAction(const int id) {
3381   return action(id);
3382 }
3383
3384 /*!
3385   \brief GEOM module message handler
3386
3387   This method can be re-implemented in the subclasses.
3388   This is a GEOM module message handler.
3389
3390   \param msg the message received.
3391 */
3392 void GeometryGUI::message(const QString& msg)
3393 {
3394   // dispatch message
3395   QStringList data = msg.split("/");
3396   const int nbStrings = data.count();
3397
3398   if (nbStrings > 0) {
3399     if (data[0] == "modified") {
3400       // get mesh entry
3401       QString anIOR = nbStrings > 1 ? data[1] : QString();
3402
3403       if ( anIOR.isEmpty() ) {
3404         return;
3405       }
3406
3407       // Get the geom object.
3408       GEOM::GEOM_Object_ptr anObj = GeometryGUI::GetObjectFromIOR (anIOR);
3409
3410       // Clear the shape buffer
3411       GeometryGUI::ClearShapeBuffer (anObj);
3412     }
3413   }
3414 }
3415
3416 /*!
3417   \brief Clears the shape buffer.
3418
3419   This is a static method. It clears the shape buffer.
3420
3421   \param theObj the object
3422 */
3423 void GeometryGUI::ClearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
3424 {
3425   if ( CORBA::is_nil( theObj ) )
3426     return;
3427
3428   CORBA::String_var IOR = SalomeApp_Application::orb()->object_to_string( theObj );
3429   TCollection_AsciiString asciiIOR( (char *)IOR.in() );
3430   GEOM_Client::get_client().RemoveShapeFromBuffer( asciiIOR );
3431
3432   SALOMEDSClient_StudyManager *aManager = SalomeApp_Application::studyMgr();
3433
3434   if (!aManager)
3435     return;
3436
3437   _PTR(Study) aStudy = aManager->GetStudyByID(theObj->GetStudyID());
3438
3439   if ( !aStudy )
3440     return;
3441
3442   _PTR(SObject) aSObj ( aStudy->FindObjectIOR( std::string( IOR ) ) );
3443   if ( !aSObj )
3444     return;
3445
3446   _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
3447   for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
3448     _PTR(GenericAttribute) anAttr;
3449     if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) {
3450       _PTR(AttributeIOR) anIOR ( anAttr );
3451       TCollection_AsciiString asciiIOR( (char*)anIOR->Value().c_str() );
3452       GEOM_Client::get_client().RemoveShapeFromBuffer( asciiIOR );
3453     }
3454   }
3455 }
3456
3457 /*!
3458   \brief Returns the object from IOR.
3459
3460   This is a static method. It returns the object from its IOR.
3461
3462   \param IOR object IOR
3463   \return GEOM object.
3464 */
3465 GEOM::GEOM_Object_ptr GeometryGUI::GetObjectFromIOR( const QString& IOR )
3466 {
3467   GEOM::GEOM_Object_var geomObj;
3468   if ( !IOR.isEmpty() ) {
3469     CORBA::Object_var corbaObj = SalomeApp_Application::orb()->string_to_object
3470       ( IOR.toLatin1().constData() );
3471     if ( !CORBA::is_nil( corbaObj ) )
3472       geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
3473   }
3474   return geomObj._retn();
3475 }
3476
3477 /*!
3478   \brief Returns IOR of the object.
3479
3480   This is a static method. It returns the object's IOR.
3481
3482   \param object the GEOM object.
3483   \return object's IOR.
3484 */
3485 QString GeometryGUI::GetIORFromObject( GEOM::GEOM_Object_ptr object )
3486 {
3487   QString IOR;
3488   if ( !CORBA::is_nil( object ) ) {
3489     CORBA::String_var anIOR =
3490       SalomeApp_Application::orb()->object_to_string( object );
3491     IOR = anIOR.in();
3492   }
3493   return IOR;
3494 }
3495
3496 /*!
3497   \brief Check if this object is can't be renamed in place
3498
3499   This method can be re-implemented in the subclasses.
3500   Return true in case if object isn't reference or component (module root).
3501
3502   \param entry column id
3503   \return \c true if the item can be renamed by the user in place (e.g. in the Object browser)
3504 */
3505 bool GeometryGUI::renameAllowed( const QString& entry) const {
3506
3507   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
3508   SalomeApp_Study* appStudy = app ? dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) : 0;
3509   SalomeApp_DataObject* obj = appStudy ? dynamic_cast<SalomeApp_DataObject*>(appStudy->findObjectByEntry(entry)) : 0;
3510
3511   return (app && appStudy && obj && !appStudy->isComponent(entry) && !obj->isReference());
3512 }
3513
3514 /*!
3515   Rename object by entry.
3516   \param entry entry of the object
3517   \param name new name of the object
3518   \brief Return \c true if rename operation finished successfully, \c false otherwise.
3519 */
3520 bool GeometryGUI::renameObject( const QString& entry, const QString& name)
3521 {
3522   bool result = false;
3523
3524   SalomeApp_Application* app =
3525     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication());
3526   SalomeApp_Study* appStudy = app ? dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) : 0;
3527
3528   if (!appStudy)
3529     return result;
3530
3531   _PTR(Study) aStudy = appStudy->studyDS();
3532
3533   if (!aStudy)
3534     return result;
3535
3536   bool aLocked = (_PTR(AttributeStudyProperties)(appStudy->studyDS()->GetProperties()))->IsLocked();
3537   if ( aLocked ) {
3538     SUIT_MessageBox::warning ( app->desktop(), QObject::tr("WRN_WARNING"), QObject::tr("WRN_STUDY_LOCKED") );
3539     return result;
3540   }
3541
3542   _PTR(SObject) obj ( aStudy->FindObjectID(qPrintable(entry)) );
3543   _PTR(GenericAttribute) anAttr;
3544   if ( obj ) {
3545     if ( obj->FindAttribute(anAttr, "AttributeName") ) {
3546       _PTR(AttributeName) aName (anAttr);
3547
3548       aName->SetValue( name.toLatin1().data() ); // rename the SObject
3549       GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(obj));
3550       if (!CORBA::is_nil(anObj)) {
3551         anObj->SetName( name.toLatin1().data() );  // Rename the corresponding GEOM_Object
3552         emit SignalDependencyTreeRenameObject( anObj->GetEntry() );
3553         emit SignalTextTreeRenameObject( entry );
3554       }
3555       result = true;
3556     }
3557   }
3558   return result;
3559 }
3560
3561 void GeometryGUI::updateMaterials()
3562 {
3563   LightApp_Preferences* pref = preferences();
3564   if ( pref ) {
3565     QStringList materials = Material_ResourceMgr::resourceMgr()->materials();
3566     QString currentMaterial = SUIT_Session::session()->resourceMgr()->stringValue( "Geometry", "material" );
3567     if ( !materials.contains( currentMaterial ) )
3568       // user material set as default in the preferences, might be removed
3569       SUIT_Session::session()->resourceMgr()->setValue( "Geometry", "material", QString( "Plastic" ) );
3570
3571     QtxPreferenceItem* prefItem = pref->rootItem()->findItem( tr( "PREF_MATERIAL" ), true );
3572     if ( prefItem ) {
3573       setPreferenceProperty( prefItem->id(),
3574                              "strings", materials );
3575       prefItem->retrieve();
3576     }
3577   }
3578 }
3579
3580 /*!
3581   \brief Check if the module allows "drag" operation of its objects.
3582
3583   Overloaded from LightApp_Module class.
3584   
3585   This function is a part of the general drag-n-drop mechanism.
3586   The goal of this function is to check data object passed as a parameter
3587   and decide if it can be dragged or no.
3588
3589   \param what data object being tested for drag operation
3590   \return \c true if module allows dragging of the specified object
3591   \sa isDropAccepted(), dropObjects()
3592 */
3593 bool GeometryGUI::isDraggable( const SUIT_DataObject* what ) const
3594 {
3595   // we allow dragging object under root and object from folder
3596   int aLevel = what->level();
3597   bool anObjectInFolder = false;
3598   if ( aLevel > 2 ) {
3599     const SalomeApp_DataObject* dataObj = dynamic_cast<const SalomeApp_DataObject*>( what );
3600     if ( dataObj ) {
3601       _PTR(SObject) aSO = dataObj->object();
3602       if ( aSO ) {
3603         _PTR(GenericAttribute) anAttr;
3604         _PTR(SObject) aFatherSO = aSO->GetStudy()->GetUseCaseBuilder()->GetFather( aSO );
3605         if ( aFatherSO && aFatherSO->FindAttribute(anAttr, "AttributeLocalID") ) {
3606           _PTR(AttributeLocalID) aLocalID( anAttr );
3607           anObjectInFolder = aLocalID->Value() == 999;
3608         }
3609       }
3610     }
3611   }
3612   return aLevel == 2 || anObjectInFolder;
3613 }
3614
3615 /*!
3616   \brief Check if the module allows "drop" operation on the given object.
3617
3618   Overloaded from LightApp_Module class.
3619
3620   This function is a part of the general drag-n-drop mechanism.
3621   The goal of this function is to check data object passed as a parameter
3622   and decide if it can be used as a target for the "drop" operation.
3623   The processing of the drop operation itself is done in the dropObjects() function.
3624
3625   \param where target data object
3626   \return \c true if module supports dropping on the \a where data object
3627   \sa isDraggable(), dropObjects()
3628 */
3629 bool GeometryGUI::isDropAccepted( const SUIT_DataObject* where ) const
3630 {
3631   // we allow dropping into folder and top-level GEOM object
3632   int aLevel = where->level();
3633   bool isFolder = false;
3634   if ( aLevel > 1 ) {
3635     const SalomeApp_DataObject* dataObj = dynamic_cast<const SalomeApp_DataObject*>( where );
3636     if ( dataObj ) {
3637       _PTR(SObject) aSO = dataObj->object();
3638       if ( aSO ) {
3639         _PTR(GenericAttribute) anAttr;
3640         if ( aSO->FindAttribute(anAttr, "AttributeLocalID") ) {
3641           _PTR(AttributeLocalID) aLocalID( anAttr );
3642           isFolder = aLocalID->Value() == 999;
3643         }
3644       }
3645     }
3646   }
3647   return aLevel == 1 || isFolder;
3648 }
3649
3650 /*!
3651   \brief Complete drag-n-drop operation.
3652   
3653   Overloaded from LightApp_Module class.
3654
3655   This function is a part of the general drag-n-drop mechanism.
3656   Its goal is to handle dropping of the objects being dragged according
3657   to the chosen operation (move). The dropping is performed in the
3658   context of the parent data object \a where and the \a row (position in the 
3659   children index) at which the data should be dropped. If \a row is equal to -1,
3660   this means that objects are added to the end of the children list.
3661
3662   \param what objects being dropped
3663   \param where target data object
3664   \param row child index at which the drop operation is performed
3665   \param action drag-n-drop operation (Qt::DropAction) - move
3666
3667   \sa isDraggable(), isDropAccepted()
3668 */
3669 void GeometryGUI::dropObjects( const DataObjectList& what, SUIT_DataObject* where,
3670                                const int row, Qt::DropAction action )
3671 {
3672   if (action != Qt::CopyAction && action != Qt::MoveAction)
3673     return; // unsupported action
3674
3675   // get parent object
3676   SalomeApp_DataObject* dataObj = dynamic_cast<SalomeApp_DataObject*>( where );
3677   if ( !dataObj ) return; // wrong parent
3678   _PTR(SObject) parentObj = dataObj->object();
3679
3680   // Find the current Study and StudyBuilder
3681   _PTR(Study) aStudy = parentObj->GetStudy();
3682   _PTR(UseCaseBuilder) aUseCaseBuilder = aStudy->GetUseCaseBuilder();
3683   // collect all parents of the target node
3684   QStringList parentIDs;
3685   _PTR(SObject) parent = parentObj;
3686   while( !parent->IsNull() ) {
3687     parentIDs << parent->GetID().c_str();
3688     parent = aUseCaseBuilder->GetFather(parent);
3689   }
3690
3691   // collect objects being dropped
3692   GEOM::object_list_var objects = new GEOM::object_list();
3693   objects->length( what.count() );
3694   int count = 0;
3695   for ( int i = 0; i < what.count(); i++ ) {
3696     dataObj = dynamic_cast<SalomeApp_DataObject*>( what[i] );
3697     if ( !dataObj ) continue;  // skip wrong objects
3698     _PTR(SObject) sobj = dataObj->object();
3699     // check that dropped object is not a parent of target object
3700     if ( parentIDs.contains( sobj->GetID().c_str() ) ) {
3701       return; // it's not allowed to move node into it's child 
3702     }
3703     objects[i] = _CAST(SObject, sobj)->GetSObject();
3704     count++;
3705   }
3706   objects->length( count );
3707
3708   // call engine function
3709   GetGeomGen()->Move( objects.in(),                              // what
3710                       _CAST(SObject, parentObj)->GetSObject(),   // where
3711                       row );                                     // row
3712
3713   // update Object browser
3714   getApp()->updateObjectBrowser( false );
3715 }
3716
3717 void GeometryGUI::emitDimensionsUpdated( QString entry )
3718 {
3719   emit DimensionsUpdated( entry );
3720 }
3721
3722 void GeometryGUI::emitAnnotationsUpdated( QString entry )
3723 {
3724   emit SignalAnnotationsUpdated( entry );
3725 }