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