]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMGUI/GeometryGUI.cxx
Salome HOME
Implementation of 0021757: EDF 1829 : Activate bring to front action on simple select...
[modules/geom.git] / src / GEOMGUI / GeometryGUI.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  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 "GEOMGUI_OCCSelector.h"
33 #include "GEOMGUI_Selection.h"
34 #include "GEOMGUI_CreationInfoWdg.h"
35 #include "GEOM_Constants.h"
36 #include "GEOM_Displayer.h"
37 #include "GEOM_AISShape.hxx"
38
39 #include "GEOM_Actor.h"
40
41 #include <Material_ResourceMgr.h>
42 #include <Material_Model.h>
43
44 #include <SUIT_Desktop.h>
45 #include <SUIT_MessageBox.h>
46 #include <SUIT_ResourceMgr.h>
47 #include <SUIT_Session.h>
48 #include <SUIT_ViewManager.h>
49
50 #include <OCCViewer_ViewWindow.h>
51 #include <OCCViewer_ViewPort3d.h>
52 #include <OCCViewer_ViewModel.h>
53 #include <OCCViewer_ViewManager.h>
54
55 #include <SOCC_ViewModel.h>
56 #include <SOCC_ViewWindow.h>
57
58 #include <SVTK_ViewWindow.h>
59 #include <SVTK_RenderWindowInteractor.h>
60 #include <SVTK_InteractorStyle.h>
61 #include <SVTK_ViewModel.h>
62
63 #include <SalomeApp_Application.h>
64 #include <SalomeApp_DataObject.h>
65 #include <SalomeApp_Study.h>
66 #include <SalomeApp_Tools.h>
67
68 #include <LightApp_SelectionMgr.h>
69 #include <LightApp_VTKSelector.h>
70 #include <LightApp_DataObject.h>
71 #include <LightApp_Preferences.h>
72
73 #include <SALOME_LifeCycleCORBA.hxx>
74 #include <SALOME_ListIO.hxx>
75 #include <SALOME_ListIteratorOfListIO.hxx>
76
77 #include <SALOMEDSClient_ClientFactory.hxx>
78 #include <SALOMEDSClient_IParameters.hxx>
79
80 #include <SALOMEDS_SObject.hxx>
81
82 #include <Basics_OCCTVersion.hxx>
83
84 // External includes
85 #include <QMenu>
86 #include <QTime>
87 #include <QAction>
88 #include <QFileInfo>
89 #include <QString>
90 #include <QPainter>
91 #include <QSignalMapper>
92
93 #include <AIS_Drawer.hxx>
94 #include <AIS_ListOfInteractive.hxx>
95 #include <AIS_ListIteratorOfListOfInteractive.hxx>
96 #include <Prs3d_Drawer.hxx>
97 #include <Prs3d_IsoAspect.hxx>
98 #include <Aspect_TypeOfMarker.hxx>
99 #include <OSD_SharedLibrary.hxx>
100 #include <NCollection_DataMap.hxx>
101
102 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
103 #include <TColStd_HArray1OfByte.hxx>
104 #else
105 #include <Graphic3d_HArray1OfBytes.hxx>
106 #endif
107
108 #include <utilities.h>
109
110 #include <vtkCamera.h>
111 #include <vtkRenderer.h>
112
113 #include <Standard_Failure.hxx>
114 #include <Standard_ErrorHandler.hxx>
115
116 #include "GEOM_version.h"
117 #include "GEOMImpl_Types.hxx" // dangerous hxx (defines short-name macros) - include after all
118
119 extern "C" {
120   Standard_EXPORT CAM_Module* createModule() {
121     return new GeometryGUI();
122   }
123
124   Standard_EXPORT char* getModuleVersion() {
125     return (char*)GEOM_VERSION_STR;
126   }
127 }
128
129 GeometryGUI::StudyTextureMap GeometryGUI::myTextureMap;
130
131 GEOM::GEOM_Gen_var GeometryGUI::myComponentGeom = GEOM::GEOM_Gen::_nil();
132
133 GEOM::GEOM_Gen_var GeometryGUI::GetGeomGen()
134 {
135   // Bug 12290: exception in Mesh GUI on GEOMBase::GetShape() if Geometry GUI hasn't been loaded
136   if (CORBA::is_nil(myComponentGeom))
137     InitGeomGen();
138   return GeometryGUI::myComponentGeom;
139 }
140
141 bool GeometryGUI::InitGeomGen()
142 {
143   GeometryGUI aGG;
144   if ( CORBA::is_nil( myComponentGeom ) ) return false;
145   return true;
146 }
147
148 //=======================================================================
149 // function : ClientSObjectToObject
150 // purpose  :
151 //=======================================================================
152 CORBA::Object_var GeometryGUI::ClientSObjectToObject (_PTR(SObject) theSObject)
153 {
154   _PTR(GenericAttribute) anAttr;
155   CORBA::Object_var anObj;
156   try {
157     std::string aValue = theSObject->GetIOR();
158     if (strcmp(aValue.c_str(), "") != 0) {
159       CORBA::ORB_ptr anORB = SalomeApp_Application::orb();
160       anObj = anORB->string_to_object(aValue.c_str());
161     }
162   } catch(...) {
163     INFOS("ClientSObjectToObject - Unknown exception was occured!!!");
164   }
165   return anObj._retn();
166 }
167
168 //=======================================================================
169 // function : ClientStudyToStudy
170 // purpose  :
171 //=======================================================================
172 SALOMEDS::Study_var GeometryGUI::ClientStudyToStudy (_PTR(Study) theStudy)
173 {
174   SALOME_NamingService *aNamingService = SalomeApp_Application::namingService();
175   CORBA::Object_var aSMObject = aNamingService->Resolve("/myStudyManager");
176   SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(aSMObject);
177   int aStudyID = theStudy->StudyId();
178   SALOMEDS::Study_var aDSStudy = aStudyManager->GetStudyByID(aStudyID);
179   return aDSStudy._retn();
180 }
181
182 void GeometryGUI::Modified (bool theIsUpdateActions)
183 {
184   if ( SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() ) ) {
185     if ( SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) ) {
186       appStudy->Modified();
187       if ( theIsUpdateActions )
188         app->updateActions();
189     }
190   }
191 }
192
193 //=======================================================================
194 // function : GeometryGUI::GeometryGUI()
195 // purpose  : Constructor
196 //=======================================================================
197 GeometryGUI::GeometryGUI() :
198   SalomeApp_Module( "GEOM" )
199 {
200   if ( CORBA::is_nil( myComponentGeom ) )
201   {
202     Engines::EngineComponent_var comp =
203       SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "GEOM" );
204     myComponentGeom = GEOM::GEOM_Gen::_narrow( comp );
205   }
206
207   myActiveDialogBox = 0;
208
209   gp_Pnt origin = gp_Pnt(0., 0., 0.);
210   gp_Dir direction = gp_Dir(0., 0., 1.);
211   myWorkingPlane = gp_Ax3(origin, direction);
212
213   myDisplayer = 0;
214   myLocalSelectionMode = GEOM_ALLOBJECTS;
215
216   myCreationInfoWdg = 0;
217
218   connect( Material_ResourceMgr::resourceMgr(), SIGNAL( changed() ), this, SLOT( updateMaterials() ) );
219 }
220
221 //=======================================================================
222 // function : GeometryGUI::~GeometryGUI()
223 // purpose  : Destructor
224 //=======================================================================
225 GeometryGUI::~GeometryGUI()
226 {
227   while (!myOCCSelectors.isEmpty())
228     delete myOCCSelectors.takeFirst();
229
230   while (!myVTKSelectors.isEmpty())
231     delete myVTKSelectors.takeFirst();
232
233   qDeleteAll(myGUIMap);
234 }
235
236 //=======================================================================
237 // function : GeometryGUI::getLibrary()
238 // purpose  : get or load GUI library by name [ internal ]
239 //=======================================================================
240 typedef GEOMGUI* (*LibraryGUI)( GeometryGUI* );
241 GEOMGUI* GeometryGUI::getLibrary( const QString& libraryName )
242 {
243   if ( !myGUIMap.contains( libraryName ) ) {
244     // try to load library if it is not loaded yet
245 #ifndef WNT
246     QString dirs = getenv( "LD_LIBRARY_PATH" );
247     QString sep  = ":";
248 #else
249     QString dirs = getenv( "PATH" );
250     QString sep  = ";";
251 #endif
252     if ( !dirs.isEmpty() ) {
253       QStringList dirList = dirs.split(sep, QString::SkipEmptyParts ); // skip empty entries
254       QListIterator<QString> it( dirList ); it.toBack();
255       while ( it.hasPrevious() ) {
256         QFileInfo fi( Qtx::addSlash( it.previous() ) + libraryName );
257         if ( fi.exists() ) {
258           OSD_SharedLibrary aSharedLibrary( fi.fileName().toLatin1().constData() );
259           bool res = aSharedLibrary.DlOpen( OSD_RTLD_LAZY );
260           if ( !res ) {
261             MESSAGE( "Can't open library : " << aSharedLibrary.DlError() );
262             continue; // continue search further
263           }
264           OSD_Function osdF = aSharedLibrary.DlSymb( "GetLibGUI" );
265           if ( osdF != NULL ) {
266             LibraryGUI func = (GEOMGUI* (*) (GeometryGUI*))osdF;
267             GEOMGUI* libGUI = (*func)( this );
268             if ( libGUI ) {
269               myGUIMap[ libraryName ] = libGUI;
270               break; // found and loaded!
271             }
272           }
273         }
274       }
275     }
276   }
277   return myGUIMap.contains( libraryName ) ? myGUIMap[ libraryName ] : 0;
278 }
279
280 //=======================================================================
281 // function : GeometryGUI::ActiveWorkingPlane()
282 // purpose  : Activate Working Plane View
283 //=======================================================================
284 void GeometryGUI::ActiveWorkingPlane()
285 {
286   gp_Dir DZ = myWorkingPlane.Direction();
287   gp_Dir DY = myWorkingPlane.YDirection();
288
289   SUIT_ViewWindow* window = application()->desktop()->activeWindow();
290   bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
291   bool ViewVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
292
293   if ( ViewOCC ) {
294     OCCViewer_ViewWindow* vw = dynamic_cast<OCCViewer_ViewWindow*>( window );
295     if ( vw ) {
296       Handle(V3d_View) view3d =  vw->getViewPort()->getView();
297
298       view3d->SetProj(DZ.X(), DZ.Y(), DZ.Z());
299       view3d->SetUp(DY.X(), DY.Y(), DY.Z());
300       vw->onViewFitAll();
301     }
302   }
303   else if ( ViewVTK ) {
304     SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( window );
305     if ( vw ) {
306       vtkCamera* camera = vw->getRenderer()->GetActiveCamera();
307
308       camera->SetPosition(DZ.X(), DZ.Y(), DZ.Z());
309       camera->SetViewUp(DY.X(), DY.Y(), DY.Z());
310       camera->SetFocalPoint(0,0,0);
311
312       vw->onFitAll();
313     }
314   }
315 }
316
317 //=======================================================================
318 // function : GeometryGUI::SetActiveDialogBox()
319 // purpose  : Set active dialog box
320 //=======================================================================
321 void GeometryGUI::SetActiveDialogBox( QDialog* aDlg )
322 {
323   myActiveDialogBox = (QDialog*)aDlg;
324 }
325
326 //=======================================================================
327 // function : GeometryGUI::EmitSignalDeactivateDialog()
328 // purpose  : Emit a signal to deactivate the active dialog Box
329 //=======================================================================
330 void GeometryGUI::EmitSignalDeactivateDialog()
331 {
332   emit SignalDeactivateActiveDialog();
333 }
334
335 //=======================================================================
336 // function : GeometryGUI::EmitSignalCloseAllDialogs()
337 // purpose  : Emit a signal to close all non modal dialogs box
338 //=======================================================================
339 void GeometryGUI::EmitSignalCloseAllDialogs()
340 {
341   emit SignalCloseAllDialogs();
342 }
343
344 //=======================================================================
345 // function : GeometryGUI::EmitSignalDefaultStepValueChanged()
346 // purpose  : Emit a signal to inform that default real spin box step has
347 //            been changed
348 //=======================================================================
349 void GeometryGUI::EmitSignalDefaultStepValueChanged(double newVal)
350 {
351   emit SignalDefaultStepValueChanged(newVal);
352 }
353
354 //=======================================================================
355 // function : GeometryGUI::OnGUIEvent()
356 // purpose  : common slot for all menu/toolbar actions
357 //=======================================================================
358 void GeometryGUI::OnGUIEvent()
359 {
360   const QObject* obj = sender();
361   if ( !obj || !obj->inherits( "QAction" ) )
362     return;
363   int id = actionId((QAction*)obj);
364   if ( id != -1 )
365     OnGUIEvent( id );
366 }
367
368 //=======================================================================
369 // function : GeometryGUI::OnGUIEvent()
370 // purpose  : manage all events on GUI [static]
371 //=======================================================================
372 void GeometryGUI::OnGUIEvent( int id, const QVariant& theParam )
373 {
374   SUIT_Application* anApp = application();
375   if (!anApp) return;
376   SUIT_Desktop* desk = anApp->desktop();
377
378   // check type of the active viewframe
379   SUIT_ViewWindow* window = desk->activeWindow();
380   bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
381   bool ViewVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
382   // if current viewframe is not of OCC and not of VTK type - return immediately
383   // fix for IPAL8958 - allow some commands to execute even when NO viewer is active (rename for example)
384   QList<int> NotViewerDependentCommands;
385   NotViewerDependentCommands << GEOMOp::OpDelete
386                              << GEOMOp::OpShow
387                              << GEOMOp::OpShowOnly
388                              << GEOMOp::OpShowOnlyChildren
389                              << GEOMOp::OpDiscloseChildren
390                              << GEOMOp::OpConcealChildren
391                              << GEOMOp::OpUnpublishObject
392                              << GEOMOp::OpPublishObject
393                              << GEOMOp::OpPointMarker
394                              << GEOMOp::OpCreateFolder
395                              << GEOMOp::OpSortChildren;
396   if ( !ViewOCC && !ViewVTK && !NotViewerDependentCommands.contains( id ) )
397       return;
398
399   // fix for IPAL9103, point 2
400   if ( CORBA::is_nil( GetGeomGen() ) ) {
401     SUIT_MessageBox::critical( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_GET_ENGINE" ), tr( "GEOM_BUT_OK" ) );
402     return;
403   }
404
405   QString libName;
406   // find corresponding GUI library
407   switch ( id ) {
408   case GEOMOp::OpOriginAndVectors:   // MENU BASIC - ORIGIN AND BASE VECTORS
409     createOriginAndBaseVectors(); // internal operation
410     return;
411   case GEOMOp::OpImport:             // MENU FILE - IMPORT
412   case GEOMOp::OpExport:             // MENU FILE - EXPORT
413   case GEOMOp::OpSelectVertex:       // POPUP MENU - SELECT ONLY - VERTEX
414   case GEOMOp::OpSelectEdge:         // POPUP MENU - SELECT ONLY - EDGE
415   case GEOMOp::OpSelectWire:         // POPUP MENU - SELECT ONLY - WIRE
416   case GEOMOp::OpSelectFace:         // POPUP MENU - SELECT ONLY - FACE
417   case GEOMOp::OpSelectShell:        // POPUP MENU - SELECT ONLY - SHELL
418   case GEOMOp::OpSelectSolid:        // POPUP MENU - SELECT ONLY - SOLID
419   case GEOMOp::OpSelectCompound:     // POPUP MENU - SELECT ONLY - COMPOUND
420   case GEOMOp::OpSelectAll:          // POPUP MENU - SELECT ONLY - SELECT ALL
421   case GEOMOp::OpDelete:             // MENU EDIT - DELETE
422   case GEOMOp::OpCheckGeom:          // MENU TOOLS - CHECK GEOMETRY
423   case GEOMOp::OpMaterialsLibrary:   // MENU TOOLS - MATERIALS LIBRARY
424   case GEOMOp::OpDeflection:         // POPUP MENU - DEFLECTION COEFFICIENT
425   case GEOMOp::OpColor:              // POPUP MENU - COLOR
426   case GEOMOp::OpSetTexture:         // POPUP MENU - SETTEXTURE
427   case GEOMOp::OpTransparency:       // POPUP MENU - TRANSPARENCY
428   case GEOMOp::OpIncrTransparency:   // SHORTCUT   - INCREASE TRANSPARENCY
429   case GEOMOp::OpDecrTransparency:   // SHORTCUT   - DECREASE TRANSPARENCY
430   case GEOMOp::OpIsos:               // POPUP MENU - ISOS
431   case GEOMOp::OpIncrNbIsos:         // SHORTCUT   - INCREASE NB ISOS
432   case GEOMOp::OpDecrNbIsos:         // SHORTCUT   - DECREASE NB ISOS
433   case GEOMOp::OpAutoColor:          // POPUP MENU - AUTO COLOR
434   case GEOMOp::OpNoAutoColor:        // POPUP MENU - DISABLE AUTO COLOR
435   case GEOMOp::OpDiscloseChildren:   // POPUP MENU - DISCLOSE CHILD ITEMS
436   case GEOMOp::OpConcealChildren:    // POPUP MENU - CONCEAL CHILD ITEMS
437   case GEOMOp::OpUnpublishObject:    // POPUP MENU - UNPUBLISH
438   case GEOMOp::OpPublishObject:      // ROOT GEOM OBJECT - POPUP MENU - PUBLISH
439   case GEOMOp::OpPointMarker:        // POPUP MENU - POINT MARKER
440   case GEOMOp::OpMaterialProperties: // POPUP MENU - MATERIAL PROPERTIES
441   case GEOMOp::OpPredefMaterial:     // POPUP MENU - <SOME MATERIAL>
442   case GEOMOp::OpPredefMaterCustom:  // POPUP MENU - MATERIAL PROPERTIES - CUSTOM...
443   case GEOMOp::OpEdgeWidth:          // POPUP MENU - LINE WIDTH - EDGE WIDTH
444   case GEOMOp::OpIsosWidth:          // POPUP MENU - LINE WIDTH - ISOS WIDTH
445   case GEOMOp::OpBringToFront:       // POPUP MENU - BRING TO FRONT
446   case GEOMOp::OpClsBringToFront:    //
447   case GEOMOp::OpCreateFolder:       // POPUP MENU - CREATE FOLDER
448   case GEOMOp::OpSortChildren:       // POPUP MENU - SORT CHILD ITEMS
449     libName = "GEOMToolsGUI";
450     break;
451   case GEOMOp::OpDMWireframe:        // MENU VIEW - WIREFRAME
452   case GEOMOp::OpDMShading:          // MENU VIEW - SHADING
453   case GEOMOp::OpDMShadingWithEdges: // MENU VIEW - SHADING
454   case GEOMOp::OpShowAll:            // MENU VIEW - SHOW ALL
455   case GEOMOp::OpShowOnly:           // MENU VIEW - DISPLAY ONLY
456   case GEOMOp::OpShowOnlyChildren:   // MENU VIEW - SHOW ONLY CHILDREN
457   case GEOMOp::OpHideAll:            // MENU VIEW - ERASE ALL
458   case GEOMOp::OpHide:               // MENU VIEW - ERASE
459   case GEOMOp::OpShow:               // MENU VIEW - DISPLAY
460   case GEOMOp::OpSwitchVectors:      // MENU VIEW - VECTOR MODE
461   case GEOMOp::OpWireframe:          // POPUP MENU - WIREFRAME
462   case GEOMOp::OpShading:            // POPUP MENU - SHADING
463   case GEOMOp::OpShadingWithEdges:   // POPUP MENU - SHADING WITH EDGES
464   case GEOMOp::OpTexture:            // POPUP MENU - TEXTURE
465   case GEOMOp::OpVectors:            // POPUP MENU - VECTORS
466     libName = "DisplayGUI";
467     break;
468   case GEOMOp::OpPoint:              // MENU BASIC - POINT
469   case GEOMOp::OpLine:               // MENU BASIC - LINE
470   case GEOMOp::OpCircle:             // MENU BASIC - CIRCLE
471   case GEOMOp::OpEllipse:            // MENU BASIC - ELLIPSE
472   case GEOMOp::OpArc:                // MENU BASIC - ARC
473   case GEOMOp::OpVector:             // MENU BASIC - VECTOR
474   case GEOMOp::OpPlane:              // MENU BASIC - PLANE
475   case GEOMOp::OpCurve:              // MENU BASIC - CURVE
476   case GEOMOp::OpLCS:                // MENU BASIC - LOCAL COORDINATE SYSTEM
477     libName = "BasicGUI";
478     break;
479   case GEOMOp::OpBox:                // MENU PRIMITIVE - BOX
480   case GEOMOp::OpCylinder:           // MENU PRIMITIVE - CYLINDER
481   case GEOMOp::OpSphere:             // MENU PRIMITIVE - SPHERE
482   case GEOMOp::OpTorus:              // MENU PRIMITIVE - TORUS
483   case GEOMOp::OpCone:               // MENU PRIMITIVE - CONE
484   case GEOMOp::OpRectangle:          // MENU PRIMITIVE - FACE
485   case GEOMOp::OpDisk:               // MENU PRIMITIVE - DISK
486     libName = "PrimitiveGUI";
487     break;
488   case GEOMOp::OpPrism:              // MENU GENERATION - PRISM
489   case GEOMOp::OpRevolution:         // MENU GENERATION - REVOLUTION
490   case GEOMOp::OpFilling:            // MENU GENERATION - FILLING
491   case GEOMOp::OpPipe:               // MENU GENERATION - PIPE
492   case GEOMOp::OpPipePath:           // MENU GENERATION - RESTORE PATH
493     libName = "GenerationGUI";
494     break;
495   case GEOMOp::Op2dSketcher:         // MENU ENTITY - SKETCHER
496   case GEOMOp::Op3dSketcher:         // MENU ENTITY - 3D SKETCHER
497   case GEOMOp::OpExplode:            // MENU ENTITY - EXPLODE
498 #ifdef WITH_OPENCV
499   case GEOMOp::OpFeatureDetect:      // MENU ENTITY - FEATURE DETECTION
500 #endif
501   case GEOMOp::OpPictureImport:      // MENU ENTITY - IMPORT PICTURE IN VIEWER
502     libName = "EntityGUI";
503     break;
504   case GEOMOp::OpEdge:               // MENU BUILD - EDGE
505   case GEOMOp::OpWire:               // MENU BUILD - WIRE
506   case GEOMOp::OpFace:               // MENU BUILD - FACE
507   case GEOMOp::OpShell:              // MENU BUILD - SHELL
508   case GEOMOp::OpSolid:              // MENU BUILD - SOLID
509   case GEOMOp::OpCompound:           // MENU BUILD - COMPUND
510     libName = "BuildGUI";
511     break;
512   case GEOMOp::OpFuse:               // MENU BOOLEAN - FUSE
513   case GEOMOp::OpCommon:             // MENU BOOLEAN - COMMON
514   case GEOMOp::OpCut:                // MENU BOOLEAN - CUT
515   case GEOMOp::OpSection:            // MENU BOOLEAN - SECTION
516     libName = "BooleanGUI";
517     break;
518   case GEOMOp::OpTranslate:          // MENU TRANSFORMATION - TRANSLATION
519   case GEOMOp::OpRotate:             // MENU TRANSFORMATION - ROTATION
520   case GEOMOp::OpChangeLoc:          // MENU TRANSFORMATION - LOCATION
521   case GEOMOp::OpMirror:             // MENU TRANSFORMATION - MIRROR
522   case GEOMOp::OpScale:              // MENU TRANSFORMATION - SCALE
523   case GEOMOp::OpOffset:             // MENU TRANSFORMATION - OFFSET
524   case GEOMOp::OpProjection:         // MENU TRANSFORMATION - PROJECTION
525   case GEOMOp::OpMultiTranslate:     // MENU TRANSFORMATION - MULTI-TRANSLATION
526   case GEOMOp::OpMultiRotate:        // MENU TRANSFORMATION - MULTI-ROTATION
527   case GEOMOp::OpReimport:           // CONTEXT(POPUP) MENU - RELOAD_IMPORTED
528     libName = "TransformationGUI";
529     break;
530   case GEOMOp::OpPartition:          // MENU OPERATION - PARTITION
531   case GEOMOp::OpArchimede:          // MENU OPERATION - ARCHIMEDE
532   case GEOMOp::OpFillet3d:           // MENU OPERATION - FILLET
533   case GEOMOp::OpChamfer:            // MENU OPERATION - CHAMFER
534   case GEOMOp::OpClipping:           // MENU OPERATION - CLIPPING RANGE
535   case GEOMOp::OpShapesOnShape:      // MENU OPERATION - GET SHAPES ON SHAPE
536   case GEOMOp::OpFillet2d:           // MENU OPERATION - FILLET 2D
537   case GEOMOp::OpFillet1d:           // MENU OPERATION - FILLET 1D
538   case GEOMOp::OpSharedShapes:       // MENU OPERATION - GET SHARED SHAPES
539   case GEOMOp::OpExtrudedBoss:       // MENU OPERATION - EXTRUDED BOSS
540   case GEOMOp::OpExtrudedCut:        // MENU OPERATION - EXTRUDED CUT
541     libName = "OperationGUI";
542     break;
543   case GEOMOp::OpSewing:             // MENU REPAIR - SEWING
544   case GEOMOp::OpSuppressFaces:      // MENU REPAIR - SUPPRESS FACES
545   case GEOMOp::OpSuppressHoles:      // MENU REPAIR - SUPPRESS HOLE
546   case GEOMOp::OpShapeProcess:       // MENU REPAIR - SHAPE PROCESSING
547   case GEOMOp::OpCloseContour:       // MENU REPAIR - CLOSE CONTOUR
548   case GEOMOp::OpRemoveIntWires:     // MENU REPAIR - REMOVE INTERNAL WIRES
549   case GEOMOp::OpAddPointOnEdge:     // MENU REPAIR - ADD POINT ON EDGE
550   case GEOMOp::OpFreeBoundaries:     // MENU MEASURE - FREE BOUNDARIES
551   case GEOMOp::OpFreeFaces:          // MENU MEASURE - FREE FACES
552   case GEOMOp::OpOrientation:        // MENU REPAIR - CHANGE ORIENTATION
553   case GEOMOp::OpGlueFaces:          // MENU REPAIR - GLUE FACES
554   case GEOMOp::OpGlueEdges:          // MENU REPAIR - GLUE EDGES
555   case GEOMOp::OpLimitTolerance:     // MENU REPAIR - LIMIT TOLERANCE
556   case GEOMOp::OpRemoveWebs:         // MENU REPAIR - REMOVE INTERNAL FACES
557   case GEOMOp::OpRemoveExtraEdges:   // MENU REPAIR - REMOVE EXTRA EDGES
558   case GEOMOp::OpFuseEdges:          // MENU REPAIR - FUSE COLLINEAR EDGES
559   case GEOMOp::OpUnionFaces:         // MENU REPAIR - UNION FACES
560     libName = "RepairGUI";
561     break;
562   case GEOMOp::OpProperties:         // MENU MEASURE - PROPERTIES
563   case GEOMOp::OpCenterMass:         // MENU MEASURE - CDG
564   case GEOMOp::OpInertia:            // MENU MEASURE - INERTIA
565   case GEOMOp::OpNormale:            // MENU MEASURE - NORMALE
566   case GEOMOp::OpBoundingBox:        // MENU MEASURE - BOUNDING BOX
567   case GEOMOp::OpMinDistance:        // MENU MEASURE - MIN DISTANCE
568   case GEOMOp::OpAngle:              // MENU MEASURE - ANGLE
569   case GEOMOp::OpTolerance:          // MENU MEASURE - TOLERANCE
570   case GEOMOp::OpWhatIs:             // MENU MEASURE - WHATIS
571   case GEOMOp::OpCheckShape:         // MENU MEASURE - CHECK
572   case GEOMOp::OpCheckCompound:      // MENU MEASURE - CHECK COMPOUND OF BLOCKS
573   case GEOMOp::OpGetNonBlocks:       // MENU MEASURE - Get NON BLOCKS
574   case GEOMOp::OpPointCoordinates:   // MENU MEASURE - POINT COORDINATES
575   case GEOMOp::OpCheckSelfInters:    // MENU MEASURE - CHECK SELF INTERSECTIONS
576     libName = "MeasureGUI";
577     break;
578   case GEOMOp::OpGroupCreate:        // MENU GROUP - CREATE
579   case GEOMOp::OpGroupCreatePopup:   // POPUP MENU - CREATE GROUP
580   case GEOMOp::OpGroupEdit:          // MENU GROUP - EDIT
581   case GEOMOp::OpGroupUnion:         // MENU GROUP - UNION
582   case GEOMOp::OpGroupIntersect:     // MENU GROUP - INTERSECT
583   case GEOMOp::OpGroupCut:           // MENU GROUP - CUT
584     libName = "GroupGUI";
585     break;
586   case GEOMOp::OpHexaSolid:          // MENU BLOCKS - HEXAHEDRAL SOLID
587   case GEOMOp::OpMultiTransform:     // MENU BLOCKS - MULTI-TRANSFORMATION
588   case GEOMOp::OpQuadFace:           // MENU BLOCKS - QUADRANGLE FACE
589   case GEOMOp::OpPropagate:          // MENU BLOCKS - PROPAGATE
590   case GEOMOp::OpExplodeBlock:       // MENU BLOCKS - EXPLODE ON BLOCKS
591     libName = "BlocksGUI";
592     break;
593   case GEOMOp::OpAdvancedNoOp:       // NO OPERATION (advanced operations base)
594   case GEOMOp::OpPipeTShape:         // MENU NEW ENTITY - ADVANCED - PIPE TSHAPE
595 //   case GEOMOp::OpPipeTShapeGroups:     // MENU NEW ENTITY - ADVANCED - PIPE TSHAPE GROUPS
596   case GEOMOp::OpDividedDisk:           // MENU NEW ENTITY - ADVANCED - DIVIDEDDISK
597   case GEOMOp::OpDividedCylinder:           // MENU NEW ENTITY - ADVANCED - DIVIDEDCYLINDER
598   case GEOMOp::OpSmoothingSurface:           // MENU NEW ENTITY - ADVANCED - SMOOTHINGSURFACE
599     //@@ 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 @@//
600     libName = "AdvancedGUI";
601     break;
602   default:
603     break;
604   }
605
606   GEOMGUI* library = 0;
607   if ( !libName.isEmpty() ) {
608 #ifndef WNT
609     libName = QString( "lib" ) + libName + ".so";
610 #else
611     libName = libName + ".dll";
612 #endif
613     library = getLibrary( libName );
614   }
615
616   // call method of corresponding GUI library
617   if ( library ) {
618     if( !theParam.isValid() )
619       library->OnGUIEvent( id, desk );
620     else
621       library->OnGUIEvent( id, desk, theParam);
622   }
623   else
624     SUIT_MessageBox::critical( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_LIB_NOT_FOUND" ), tr( "GEOM_BUT_OK" ) );
625
626   updateCreationInfo();
627 }
628
629 //=================================================================================
630 // function : GeometryGUI::OnKeyPress()
631 // purpose  : Called when any key is pressed by user [static]
632 //=================================================================================
633 void GeometryGUI::OnKeyPress( SUIT_ViewWindow* w, QKeyEvent* e )
634 {
635   if ( !application() )
636     return;
637   foreach ( GEOMGUI* lib, myGUIMap )
638     lib->OnKeyPress( e, application()->desktop(), w );
639 }
640
641 //=================================================================================
642 // function : GeometryGUI::OnMouseMove()
643 // purpose  : Manages mouse move events [static]
644 //=================================================================================
645 void GeometryGUI::OnMouseMove( SUIT_ViewWindow* w, QMouseEvent* e )
646 {
647   if ( !application() )
648     return;
649   foreach ( GEOMGUI* lib, myGUIMap )
650     lib->OnMouseMove( e, application()->desktop(), w );
651 }
652
653 //=================================================================================
654 // function : GeometryGUI::OnMouseRelease()
655 // purpose  : Manages mouse release events [static]
656 //=================================================================================
657 void GeometryGUI::OnMouseRelease( SUIT_ViewWindow* w, QMouseEvent* e )
658 {
659   if ( !application() )
660     return;
661   foreach ( GEOMGUI* lib, myGUIMap )
662     lib->OnMouseRelease( e, application()->desktop(), w );
663 }
664
665 //=================================================================================
666 // function : GeometryGUI::OnMousePress()
667 // purpose  : Manage mouse press events [static]
668 //=================================================================================
669 void GeometryGUI::OnMousePress( SUIT_ViewWindow* w, QMouseEvent* e )
670 {
671   if ( !application() )
672     return;
673   foreach ( GEOMGUI* lib, myGUIMap )
674     lib->OnMousePress( e, application()->desktop(), w );
675 }
676
677 //=======================================================================
678 // function : createGeomAction
679 // purpose  :
680 //=======================================================================
681 void GeometryGUI::createGeomAction( const int id, const QString& label, const QString& icolabel,
682                                     const int accel, const bool toggle, const QString& shortcutAction )
683 {
684   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
685   QPixmap icon = icolabel.isEmpty() ? resMgr->loadPixmap( "GEOM", tr( (QString( "ICO_" )+label).toLatin1().constData() ), false )
686                                     : resMgr->loadPixmap( "GEOM", tr( icolabel.toLatin1().constData() ) );
687   createAction( id,
688                 tr( QString( "TOP_%1" ).arg( label ).toLatin1().constData() ),
689                 icon,
690                 tr( QString( "MEN_%1" ).arg( label ).toLatin1().constData() ),
691                 tr( QString( "STB_%1" ).arg( label ).toLatin1().constData() ),
692                 accel,
693                 application()->desktop(),
694                 toggle,
695                 this, SLOT( OnGUIEvent() ),
696                 shortcutAction );
697 }
698
699 //=======================================================================
700 // function : createOriginAndBaseVectors
701 // purpose  :
702 //=======================================================================
703 void GeometryGUI::createOriginAndBaseVectors()
704 {
705   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
706   if ( appStudy ) {
707     _PTR(Study) studyDS = appStudy->studyDS();
708     if ( studyDS && !CORBA::is_nil( GetGeomGen() ) ) {
709       GEOM::GEOM_IBasicOperations_var aBasicOperations = GetGeomGen()->GetIBasicOperations( studyDS->StudyId() );
710       if ( !aBasicOperations->_is_nil() ) {
711         SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
712         double aLength = aResourceMgr->doubleValue( "Geometry", "base_vectors_length", 1.0 );
713         GEOM::GEOM_Object_var anOrigin = aBasicOperations->MakePointXYZ( 0.0, 0.0, 0.0 );
714         GEOM::GEOM_Object_var anOX = aBasicOperations->MakeVectorDXDYDZ( aLength, 0.0, 0.0 );
715         GEOM::GEOM_Object_var anOY = aBasicOperations->MakeVectorDXDYDZ( 0.0, aLength, 0.0 );
716         GEOM::GEOM_Object_var anOZ = aBasicOperations->MakeVectorDXDYDZ( 0.0, 0.0, aLength );
717
718         SALOMEDS::Study_var aDSStudy = ClientStudyToStudy( studyDS );
719         GetGeomGen()->PublishInStudy( aDSStudy, SALOMEDS::SObject::_nil(), anOrigin, "O" );
720         GetGeomGen()->PublishInStudy( aDSStudy, SALOMEDS::SObject::_nil(), anOX, "OX" );
721         GetGeomGen()->PublishInStudy( aDSStudy, SALOMEDS::SObject::_nil(), anOY, "OY" );
722         GetGeomGen()->PublishInStudy( aDSStudy, SALOMEDS::SObject::_nil(), anOZ, "OZ" );
723
724         getApp()->updateObjectBrowser( true );
725       }
726     }
727   }
728 }
729
730 //=======================================================================
731 // function : GeometryGUI::initialize()
732 // purpose  : Called when GEOM module is created
733 //=======================================================================
734 void GeometryGUI::initialize( CAM_Application* app )
735 {
736   SalomeApp_Module::initialize( app );
737
738   // ----- create actions --------------
739
740   createGeomAction( GEOMOp::OpImport,     "IMPORT", "", Qt::ControlModifier + Qt::Key_I );
741   createGeomAction( GEOMOp::OpExport,     "EXPORT", "", Qt::ControlModifier + Qt::Key_E );
742
743   createGeomAction( GEOMOp::OpDelete,     "DELETE", "", Qt::Key_Delete );
744
745   createGeomAction( GEOMOp::OpPoint,      "POINT" );
746   createGeomAction( GEOMOp::OpLine,       "LINE" );
747   createGeomAction( GEOMOp::OpCircle,     "CIRCLE" );
748   createGeomAction( GEOMOp::OpEllipse,    "ELLIPSE" );
749   createGeomAction( GEOMOp::OpArc,        "ARC" );
750   createGeomAction( GEOMOp::OpCurve,      "CURVE" );
751   createGeomAction( GEOMOp::OpVector,     "VECTOR" );
752   createGeomAction( GEOMOp::OpPlane,      "PLANE" );
753   createGeomAction( GEOMOp::OpLCS,        "LOCAL_CS" );
754   createGeomAction( GEOMOp::OpOriginAndVectors, "ORIGIN_AND_VECTORS" );
755
756   createGeomAction( GEOMOp::OpBox,        "BOX" );
757   createGeomAction( GEOMOp::OpCylinder,   "CYLINDER" );
758   createGeomAction( GEOMOp::OpSphere,     "SPHERE" );
759   createGeomAction( GEOMOp::OpTorus,      "TORUS" );
760   createGeomAction( GEOMOp::OpCone,       "CONE" );
761   createGeomAction( GEOMOp::OpRectangle,  "RECTANGLE" );
762   createGeomAction( GEOMOp::OpDisk,       "DISK" );
763
764   createGeomAction( GEOMOp::OpPrism,       "EXTRUSION" );
765   createGeomAction( GEOMOp::OpRevolution,  "REVOLUTION" );
766   createGeomAction( GEOMOp::OpFilling,     "FILLING" );
767   createGeomAction( GEOMOp::OpPipe,        "PIPE" );
768   createGeomAction( GEOMOp::OpPipePath,    "PIPE_PATH" );
769
770   createGeomAction( GEOMOp::OpGroupCreate, "GROUP_CREATE" );
771   createGeomAction( GEOMOp::OpGroupEdit,   "GROUP_EDIT" );
772   createGeomAction( GEOMOp::OpGroupUnion,  "GROUP_UNION" );
773   createGeomAction( GEOMOp::OpGroupIntersect, "GROUP_INTERSECT" );
774   createGeomAction( GEOMOp::OpGroupCut,    "GROUP_CUT" );
775
776   createGeomAction( GEOMOp::OpReimport,    "RELOAD_IMPORTED" );
777
778   createGeomAction( GEOMOp::OpQuadFace,    "Q_FACE" );
779   createGeomAction( GEOMOp::OpHexaSolid,   "HEX_SOLID" );
780
781   createGeomAction( GEOMOp::Op2dSketcher,  "SKETCH" );
782   createGeomAction( GEOMOp::Op3dSketcher,  "3DSKETCH" );
783   createGeomAction( GEOMOp::OpExplode,     "EXPLODE" );
784 #ifdef WITH_OPENCV
785   createGeomAction( GEOMOp::OpFeatureDetect,"FEATURE_DETECTION" );
786 #endif
787   createGeomAction( GEOMOp::OpPictureImport,"PICTURE_IMPORT" );
788
789   createGeomAction( GEOMOp::OpEdge,        "EDGE" );
790   createGeomAction( GEOMOp::OpWire,        "WIRE" );
791   createGeomAction( GEOMOp::OpFace,        "FACE" );
792   createGeomAction( GEOMOp::OpShell,       "SHELL" );
793   createGeomAction( GEOMOp::OpSolid,       "SOLID" );
794   createGeomAction( GEOMOp::OpCompound,    "COMPOUND" );
795
796   createGeomAction( GEOMOp::OpFuse,        "FUSE" );
797   createGeomAction( GEOMOp::OpCommon,      "COMMON" );
798   createGeomAction( GEOMOp::OpCut,         "CUT" );
799   createGeomAction( GEOMOp::OpSection,     "SECTION" );
800
801   createGeomAction( GEOMOp::OpTranslate,      "TRANSLATION" );
802   createGeomAction( GEOMOp::OpRotate,         "ROTATION" );
803   createGeomAction( GEOMOp::OpChangeLoc,      "MODIFY_LOCATION" );
804   createGeomAction( GEOMOp::OpMirror,         "MIRROR" );
805   createGeomAction( GEOMOp::OpScale,          "SCALE" );
806   createGeomAction( GEOMOp::OpOffset,         "OFFSET" );
807   createGeomAction( GEOMOp::OpProjection,     "PROJECTION" );
808   createGeomAction( GEOMOp::OpMultiTranslate, "MUL_TRANSLATION" );
809   createGeomAction( GEOMOp::OpMultiRotate,    "MUL_ROTATION" );
810
811   createGeomAction( GEOMOp::OpPartition,      "PARTITION" );
812   createGeomAction( GEOMOp::OpArchimede,      "ARCHIMEDE" );
813   createGeomAction( GEOMOp::OpFillet3d,       "FILLET" );
814   createGeomAction( GEOMOp::OpChamfer,        "CHAMFER" );
815   //createGeomAction( GEOMOp::OpClipping,        "CLIPPING" );
816   createGeomAction( GEOMOp::OpShapesOnShape,  "GET_SHAPES_ON_SHAPE" );
817   createGeomAction( GEOMOp::OpSharedShapes,   "GET_SHARED_SHAPES" );
818   createGeomAction( GEOMOp::OpExtrudedCut,    "EXTRUDED_CUT" );
819   createGeomAction( GEOMOp::OpExtrudedBoss,   "EXTRUDED_BOSS" );
820   createGeomAction( GEOMOp::OpFillet1d,       "FILLET_1D" );
821   createGeomAction( GEOMOp::OpFillet2d,       "FILLET_2D" );
822
823   createGeomAction( GEOMOp::OpMultiTransform, "MUL_TRANSFORM" );
824   createGeomAction( GEOMOp::OpExplodeBlock,   "EXPLODE_BLOCKS" );
825   createGeomAction( GEOMOp::OpPropagate,      "PROPAGATE" );
826
827   createGeomAction( GEOMOp::OpSewing,           "SEWING" );
828   createGeomAction( GEOMOp::OpGlueFaces,        "GLUE_FACES" );
829   createGeomAction( GEOMOp::OpGlueEdges,        "GLUE_EDGES" );
830   createGeomAction( GEOMOp::OpLimitTolerance,   "LIMIT_TOLERANCE" );
831   createGeomAction( GEOMOp::OpSuppressFaces,    "SUPPRESS_FACES" );
832   createGeomAction( GEOMOp::OpSuppressHoles,    "SUPPERSS_HOLES" );
833   createGeomAction( GEOMOp::OpShapeProcess,     "SHAPE_PROCESS" );
834   createGeomAction( GEOMOp::OpCloseContour,     "CLOSE_CONTOUR" );
835   createGeomAction( GEOMOp::OpRemoveIntWires,   "SUPPRESS_INT_WIRES" );
836   createGeomAction( GEOMOp::OpAddPointOnEdge,   "POINT_ON_EDGE" );
837   createGeomAction( GEOMOp::OpFreeBoundaries,   "CHECK_FREE_BNDS" );
838   createGeomAction( GEOMOp::OpFreeFaces,        "CHECK_FREE_FACES" );
839   createGeomAction( GEOMOp::OpOrientation,      "CHANGE_ORIENTATION" );
840   createGeomAction( GEOMOp::OpRemoveWebs,       "REMOVE_WEBS" );
841   createGeomAction( GEOMOp::OpRemoveExtraEdges, "REMOVE_EXTRA_EDGES" );
842   createGeomAction( GEOMOp::OpFuseEdges,        "FUSE_EDGES" );
843   createGeomAction( GEOMOp::OpUnionFaces,       "UNION_FACES" );
844
845   createGeomAction( GEOMOp::OpPointCoordinates, "POINT_COORDS" );
846   createGeomAction( GEOMOp::OpProperties,       "BASIC_PROPS" );
847   createGeomAction( GEOMOp::OpCenterMass,       "MASS_CENTER" );
848   createGeomAction( GEOMOp::OpInertia,          "INERTIA" );
849   createGeomAction( GEOMOp::OpNormale,          "NORMALE" );
850   createGeomAction( GEOMOp::OpBoundingBox,      "BND_BOX" );
851   createGeomAction( GEOMOp::OpMinDistance,      "MIN_DIST" );
852   createGeomAction( GEOMOp::OpAngle,            "MEASURE_ANGLE" );
853
854   createGeomAction( GEOMOp::OpTolerance,        "TOLERANCE" );
855   createGeomAction( GEOMOp::OpWhatIs,           "WHAT_IS" );
856   createGeomAction( GEOMOp::OpCheckShape,       "CHECK" );
857   createGeomAction( GEOMOp::OpCheckCompound,    "CHECK_COMPOUND" );
858   createGeomAction( GEOMOp::OpGetNonBlocks,     "GET_NON_BLOCKS" );
859   createGeomAction( GEOMOp::OpCheckSelfInters,  "CHECK_SELF_INTERSECTIONS" );
860
861 #ifdef _DEBUG_ // PAL16821
862   createGeomAction( GEOMOp::OpCheckGeom,        "CHECK_GEOMETRY" );
863 #endif
864
865   createGeomAction( GEOMOp::OpMaterialsLibrary,   "MATERIALS_LIBRARY" );
866   createGeomAction( GEOMOp::OpDMWireframe,        "WIREFRAME" );
867   createGeomAction( GEOMOp::OpDMShading,          "SHADING" );
868   createGeomAction( GEOMOp::OpDMShadingWithEdges, "SHADING_WITH_EDGES" );
869   createGeomAction( GEOMOp::OpShowAll,          "DISPLAY_ALL" );
870   createGeomAction( GEOMOp::OpHideAll,          "ERASE_ALL" );
871   createGeomAction( GEOMOp::OpShow,             "DISPLAY" );
872   createGeomAction( GEOMOp::OpSwitchVectors,    "VECTOR_MODE");
873   createGeomAction( GEOMOp::OpSelectVertex,     "VERTEX_SEL_ONLY" ,"", 0, true );
874   createGeomAction( GEOMOp::OpSelectEdge,       "EDGE_SEL_ONLY", "", 0, true );
875   createGeomAction( GEOMOp::OpSelectWire,       "WIRE_SEL_ONLY", "",  0, true );
876   createGeomAction( GEOMOp::OpSelectFace,       "FACE_SEL_ONLY", "", 0, true );
877   createGeomAction( GEOMOp::OpSelectShell,      "SHELL_SEL_ONLY", "",  0, true );
878   createGeomAction( GEOMOp::OpSelectSolid,      "SOLID_SEL_ONLY", "", 0, true );
879   createGeomAction( GEOMOp::OpSelectCompound,   "COMPOUND_SEL_ONLY", "",  0, true );
880   createGeomAction( GEOMOp::OpSelectAll,        "ALL_SEL_ONLY", "",  0, true );
881   createGeomAction( GEOMOp::OpShowOnly,         "DISPLAY_ONLY" );
882   createGeomAction( GEOMOp::OpShowOnlyChildren, "SHOW_ONLY_CHILDREN" );
883   createGeomAction( GEOMOp::OpBringToFront,     "BRING_TO_FRONT", "", 0, true );
884   createGeomAction( GEOMOp::OpClsBringToFront,  "CLS_BRING_TO_FRONT" );
885   createGeomAction( GEOMOp::OpHide,             "ERASE" );
886
887   createGeomAction( GEOMOp::OpWireframe,        "POP_WIREFRAME", "", 0, true );
888   createGeomAction( GEOMOp::OpShading,          "POP_SHADING", "", 0, true );
889   createGeomAction( GEOMOp::OpShadingWithEdges, "POP_SHADING_WITH_EDGES", "", 0, true );
890   createGeomAction( GEOMOp::OpTexture,          "POP_TEXTURE", "", 0, true );
891   createGeomAction( GEOMOp::OpEdgeWidth,        "EDGE_WIDTH");
892   createGeomAction( GEOMOp::OpIsosWidth,        "ISOS_WIDTH");
893   createGeomAction( GEOMOp::OpVectors,          "POP_VECTORS", "", 0, true );
894   createGeomAction( GEOMOp::OpDeflection,       "POP_DEFLECTION" );
895   createGeomAction( GEOMOp::OpColor,            "POP_COLOR" );
896   createGeomAction( GEOMOp::OpSetTexture,       "POP_SETTEXTURE" );
897   createGeomAction( GEOMOp::OpTransparency,     "POP_TRANSPARENCY" );
898   createGeomAction( GEOMOp::OpIsos,             "POP_ISOS" );
899   createGeomAction( GEOMOp::OpAutoColor,        "POP_AUTO_COLOR" );
900   createGeomAction( GEOMOp::OpNoAutoColor,      "POP_DISABLE_AUTO_COLOR" );
901   createGeomAction( GEOMOp::OpGroupCreatePopup, "POP_CREATE_GROUP" );
902   createGeomAction( GEOMOp::OpDiscloseChildren, "POP_DISCLOSE_CHILDREN" );
903   createGeomAction( GEOMOp::OpConcealChildren,  "POP_CONCEAL_CHILDREN" );
904   createGeomAction( GEOMOp::OpUnpublishObject,  "POP_UNPUBLISH_OBJ" );
905   createGeomAction( GEOMOp::OpPublishObject,    "POP_PUBLISH_OBJ" );
906   createGeomAction( GEOMOp::OpPointMarker,      "POP_POINT_MARKER" );
907   createGeomAction( GEOMOp::OpMaterialProperties,   "POP_MATERIAL_PROPERTIES" );
908   createGeomAction( GEOMOp::OpPredefMaterCustom,    "POP_PREDEF_MATER_CUSTOM" );
909   createGeomAction( GEOMOp::OpCreateFolder, "POP_CREATE_FOLDER" );
910   createGeomAction( GEOMOp::OpSortChildren, "POP_SORT_CHILD_ITEMS" );
911
912   createGeomAction( GEOMOp::OpPipeTShape, "PIPETSHAPE" );
913
914   // Create actions for increase/decrease transparency shortcuts
915   createGeomAction( GEOMOp::OpIncrTransparency, "", "", 0, false,
916                     "Geometry:Increase transparency");
917   createGeomAction( GEOMOp::OpDecrTransparency, "", "", 0, false,
918                     "Geometry:Decrease transparency");
919
920   // Create actions for increase/decrease number of isolines
921   createGeomAction( GEOMOp::OpIncrNbIsos, "", "", 0, false,
922                     "Geometry:Increase number of isolines");
923   createGeomAction( GEOMOp::OpDecrNbIsos, "", "", 0, false,
924                     "Geometry:Decrease number of isolines");
925
926 //   createGeomAction( GEOMOp::OpPipeTShapeGroups, "PIPETSHAPEGROUPS" );
927   createGeomAction( GEOMOp::OpDividedDisk, "DIVIDEDDISK" );
928   createGeomAction( GEOMOp::OpDividedCylinder, "DIVIDEDCYLINDER" );
929   createGeomAction( GEOMOp::OpSmoothingSurface, "SMOOTHINGSURFACE" );
930   //@@ 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 @@//
931
932   // ---- create menus --------------------------
933
934   int fileId = createMenu( tr( "MEN_FILE" ), -1, -1 );
935   createMenu( separator(),      fileId, 10 );
936   createMenu( GEOMOp::OpImport, fileId, 10 );
937   createMenu( GEOMOp::OpExport, fileId, 10 );
938   createMenu( separator(),      fileId, -1 );
939
940   int editId = createMenu( tr( "MEN_EDIT" ), -1, -1 );
941   createMenu( GEOMOp::OpDelete, editId, -1 );
942
943   int newEntId = createMenu( tr( "MEN_NEW_ENTITY" ), -1, -1, 10 );
944
945   int basicId = createMenu( tr( "MEN_BASIC" ), newEntId, -1 );
946   createMenu( GEOMOp::OpPoint,   basicId, -1 );
947   createMenu( GEOMOp::OpLine,    basicId, -1 );
948   createMenu( GEOMOp::OpCircle,  basicId, -1 );
949   createMenu( GEOMOp::OpEllipse, basicId, -1 );
950   createMenu( GEOMOp::OpArc,     basicId, -1 );
951   createMenu( GEOMOp::OpCurve,   basicId, -1 );
952   createMenu( GEOMOp::Op2dSketcher, basicId, -1 );
953   createMenu( GEOMOp::Op3dSketcher, basicId, -1 );
954   createMenu( separator(),       basicId, -1 );
955   createMenu( GEOMOp::OpVector,  basicId, -1 );
956   createMenu( GEOMOp::OpPlane,   basicId, -1 );
957   createMenu( GEOMOp::OpLCS,     basicId, -1 );
958   createMenu( GEOMOp::OpOriginAndVectors, basicId, -1 );
959
960   int primId = createMenu( tr( "MEN_PRIMITIVES" ), newEntId, -1 );
961   createMenu( GEOMOp::OpBox,       primId, -1 );
962   createMenu( GEOMOp::OpCylinder,  primId, -1 );
963   createMenu( GEOMOp::OpSphere,    primId, -1 );
964   createMenu( GEOMOp::OpTorus,     primId, -1 );
965   createMenu( GEOMOp::OpCone,      primId, -1 );
966   createMenu( GEOMOp::OpRectangle, primId, -1 );
967   createMenu( GEOMOp::OpDisk,      primId, -1 );
968   createMenu( GEOMOp::OpPipeTShape,primId, -1 );
969
970   int genId = createMenu( tr( "MEN_GENERATION" ), newEntId, -1 );
971   createMenu( GEOMOp::OpPrism,      genId, -1 );
972   createMenu( GEOMOp::OpRevolution, genId, -1 );
973   createMenu( GEOMOp::OpFilling,    genId, -1 );
974   createMenu( GEOMOp::OpPipe,       genId, -1 );
975 #if OCC_VERSION_LARGE > 0x06050300
976   createMenu( GEOMOp::OpPipePath,   genId, -1 );
977 #endif
978
979    int advId = createMenu( tr( "MEN_ADVANCED" ), newEntId, -1 );
980    createMenu( GEOMOp::OpSmoothingSurface, advId, -1 );
981    //@@ 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 @@//
982
983   createMenu( separator(), newEntId, -1 );
984
985   int groupId = createMenu( tr( "MEN_GROUP" ), newEntId, -1 );
986   createMenu( GEOMOp::OpGroupCreate,    groupId, -1 );
987   createMenu( GEOMOp::OpGroupEdit,      groupId, -1 );
988   createMenu( GEOMOp::OpGroupUnion,     groupId, -1 );
989   createMenu( GEOMOp::OpGroupIntersect, groupId, -1 );
990   createMenu( GEOMOp::OpGroupCut,       groupId, -1 );
991
992   createMenu( separator(), newEntId, -1 );
993
994   int blocksId = createMenu( tr( "MEN_BLOCKS" ), newEntId, -1 );
995   createMenu( GEOMOp::OpQuadFace,        blocksId, -1 );
996   createMenu( GEOMOp::OpHexaSolid,       blocksId, -1 );
997   createMenu( GEOMOp::OpDividedDisk,     blocksId, -1 );
998   createMenu( GEOMOp::OpDividedCylinder, blocksId, -1 );
999
1000   createMenu( separator(),          newEntId, -1 );
1001
1002   createMenu( GEOMOp::OpExplode,    newEntId, -1 );
1003
1004   int buildId = createMenu( tr( "MEN_BUILD" ), newEntId, -1 );
1005   createMenu( GEOMOp::OpEdge,     buildId, -1 );
1006   createMenu( GEOMOp::OpWire,     buildId, -1 );
1007   createMenu( GEOMOp::OpFace,     buildId, -1 );
1008   createMenu( GEOMOp::OpShell,    buildId, -1 );
1009   createMenu( GEOMOp::OpSolid,    buildId, -1 );
1010   createMenu( GEOMOp::OpCompound, buildId, -1 );
1011
1012   createMenu( separator(),          newEntId, -1 );
1013
1014   createMenu( GEOMOp::OpPictureImport, newEntId, -1 );
1015 #ifdef WITH_OPENCV
1016   createMenu( GEOMOp::OpFeatureDetect, newEntId, -1 );
1017 #endif
1018
1019   int operId = createMenu( tr( "MEN_OPERATIONS" ), -1, -1, 10 );
1020
1021   int boolId = createMenu( tr( "MEN_BOOLEAN" ), operId, -1 );
1022   createMenu( GEOMOp::OpFuse,    boolId, -1 );
1023   createMenu( GEOMOp::OpCommon,  boolId, -1 );
1024   createMenu( GEOMOp::OpCut,     boolId, -1 );
1025   createMenu( GEOMOp::OpSection, boolId, -1 );
1026
1027   int transId = createMenu( tr( "MEN_TRANSFORMATION" ), operId, -1 );
1028   createMenu( GEOMOp::OpTranslate,      transId, -1 );
1029   createMenu( GEOMOp::OpRotate,         transId, -1 );
1030   createMenu( GEOMOp::OpChangeLoc,      transId, -1 );
1031   createMenu( GEOMOp::OpMirror,         transId, -1 );
1032   createMenu( GEOMOp::OpScale,          transId, -1 );
1033   createMenu( GEOMOp::OpOffset,         transId, -1 );
1034   createMenu( GEOMOp::OpProjection,     transId, -1 );
1035   createMenu( separator(),              transId, -1 );
1036   createMenu( GEOMOp::OpMultiTranslate, transId, -1 );
1037   createMenu( GEOMOp::OpMultiRotate,    transId, -1 );
1038
1039   int blockId = createMenu( tr( "MEN_BLOCKS" ), operId, -1 );
1040   createMenu( GEOMOp::OpMultiTransform, blockId, -1 );
1041   createMenu( GEOMOp::OpExplodeBlock,   blockId, -1 );
1042   createMenu( GEOMOp::OpPropagate,      blockId, -1 );
1043
1044   createMenu( separator(), operId, -1 );
1045
1046   createMenu( GEOMOp::OpPartition,     operId, -1 );
1047   createMenu( GEOMOp::OpArchimede,     operId, -1 );
1048   createMenu( GEOMOp::OpShapesOnShape, operId, -1 );
1049   createMenu( GEOMOp::OpSharedShapes,  operId, -1 );
1050
1051   createMenu( separator(), operId, -1 );
1052
1053   createMenu( GEOMOp::OpFillet1d,      operId, -1 );
1054   createMenu( GEOMOp::OpFillet2d,      operId, -1 );
1055   createMenu( GEOMOp::OpFillet3d,      operId, -1 );
1056   createMenu( GEOMOp::OpChamfer,       operId, -1 );
1057   createMenu( GEOMOp::OpExtrudedBoss,  operId, -1 );
1058   createMenu( GEOMOp::OpExtrudedCut,   operId, -1 );
1059   //createMenu( GEOMOp::OpClipping,      operId, -1 );
1060
1061   int repairId = createMenu( tr( "MEN_REPAIR" ), -1, -1, 10 );
1062   createMenu( GEOMOp::OpShapeProcess,    repairId, -1 );
1063   createMenu( GEOMOp::OpSuppressFaces,   repairId, -1 );
1064   createMenu( GEOMOp::OpCloseContour,    repairId, -1 );
1065   createMenu( GEOMOp::OpRemoveIntWires,  repairId, -1 );
1066   createMenu( GEOMOp::OpSuppressHoles,   repairId, -1 );
1067   createMenu( GEOMOp::OpSewing,          repairId, -1 );
1068   createMenu( GEOMOp::OpGlueFaces,       repairId, -1 );
1069   createMenu( GEOMOp::OpGlueEdges,       repairId, -1 );
1070   createMenu( GEOMOp::OpLimitTolerance,  repairId, -1 );
1071   createMenu( GEOMOp::OpAddPointOnEdge,  repairId, -1 );
1072   //createMenu( GEOMOp::OpFreeBoundaries,  repairId, -1 );
1073   //createMenu( GEOMOp::OpFreeFaces,       repairId, -1 );
1074   createMenu( GEOMOp::OpOrientation,      repairId, -1 );
1075   createMenu( GEOMOp::OpRemoveWebs,       repairId, -1 );
1076   createMenu( GEOMOp::OpRemoveExtraEdges, repairId, -1 );
1077   createMenu( GEOMOp::OpFuseEdges,        repairId, -1 );
1078   createMenu( GEOMOp::OpUnionFaces,       repairId, -1 );
1079
1080   int measurId = createMenu( tr( "MEN_MEASURES" ), -1, -1, 10 );
1081   createMenu( GEOMOp::OpPointCoordinates, measurId, -1 );
1082   createMenu( GEOMOp::OpProperties,       measurId, -1 );
1083   createMenu( separator(),                measurId, -1 );
1084   createMenu( GEOMOp::OpCenterMass,       measurId, -1 );
1085   createMenu( GEOMOp::OpInertia,          measurId, -1 );
1086   createMenu( GEOMOp::OpNormale,          measurId, -1 );
1087   createMenu( separator(),                measurId, -1 );
1088   createMenu( GEOMOp::OpFreeBoundaries,   measurId, -1 );
1089   createMenu( GEOMOp::OpFreeFaces,        measurId, -1 );
1090   createMenu( separator(),                measurId, -1 );
1091
1092   int dimId = createMenu( tr( "MEN_DIMENSIONS" ), measurId, -1 );
1093   createMenu( GEOMOp::OpBoundingBox, dimId, -1 );
1094   createMenu( GEOMOp::OpMinDistance, dimId, -1 );
1095   createMenu( GEOMOp::OpAngle,       dimId, -1 );
1096
1097   createMenu( separator(),               measurId, -1 );
1098   createMenu( GEOMOp::OpTolerance,       measurId, -1 );
1099   createMenu( separator(),               measurId, -1 );
1100   createMenu( GEOMOp::OpWhatIs,          measurId, -1 );
1101   createMenu( GEOMOp::OpCheckShape,      measurId, -1 );
1102   createMenu( GEOMOp::OpCheckCompound,   measurId, -1 );
1103   createMenu( GEOMOp::OpGetNonBlocks,    measurId, -1 );
1104   createMenu( GEOMOp::OpCheckSelfInters, measurId, -1 );
1105
1106   int toolsId = createMenu( tr( "MEN_TOOLS" ), -1, -1, 50 );
1107 #if defined(_DEBUG_) || defined(_DEBUG) // PAL16821
1108   createMenu( separator(),         toolsId, -1 );
1109   createMenu( GEOMOp::OpCheckGeom, toolsId, -1 );
1110 #endif
1111  
1112   createMenu( separator(),         toolsId, -1 );
1113   createMenu( GEOMOp::OpMaterialsLibrary, toolsId, -1 );
1114   createMenu( separator(),         toolsId, -1 );
1115
1116   int viewId = createMenu( tr( "MEN_VIEW" ), -1, -1 );
1117   createMenu( separator(),       viewId, -1 );
1118
1119   int dispmodeId = createMenu( tr( "MEN_DISPLAY_MODE" ), viewId, -1 );
1120   createMenu( GEOMOp::OpDMWireframe,        dispmodeId, -1 );
1121   createMenu( GEOMOp::OpDMShading,          dispmodeId, -1 );
1122   createMenu( GEOMOp::OpDMShadingWithEdges, dispmodeId, -1 );
1123   createMenu( separator(),                  dispmodeId, -1 );
1124   createMenu( GEOMOp::OpSwitchVectors,      dispmodeId, -1 );
1125
1126   createMenu( separator(),       viewId, -1 );
1127   createMenu( GEOMOp::OpShowAll, viewId, -1 );
1128   createMenu( GEOMOp::OpHideAll, viewId, -1 );
1129   createMenu( separator(),       viewId, -1 );
1130   createMenu( GEOMOp::OpPublishObject, viewId, -1 );
1131   createMenu( separator(),       viewId, -1 );
1132
1133 /*
1134   PAL9111:
1135   because of these items are accessible through object browser and viewers
1136   we have removed they from main menu
1137
1138   createMenu( GEOMOp::OpShow, viewId, -1 );
1139   createMenu( GEOMOp::OpShowOnly, viewId, -1 );
1140   createMenu( GEOMOp::OpHide, viewId, -1 );
1141 */
1142
1143   // ---- create toolbars --------------------------
1144
1145   int basicTbId = createTool( tr( "TOOL_BASIC" ) );
1146   createTool( GEOMOp::OpPoint,      basicTbId );
1147   createTool( GEOMOp::OpLine,       basicTbId );
1148   createTool( GEOMOp::OpCircle,     basicTbId );
1149   createTool( GEOMOp::OpEllipse,    basicTbId );
1150   createTool( GEOMOp::OpArc,        basicTbId );
1151   createTool( GEOMOp::OpCurve,      basicTbId );
1152   createTool( GEOMOp::OpVector,     basicTbId );
1153   createTool( GEOMOp::Op2dSketcher, basicTbId ); //rnc
1154   createTool( GEOMOp::Op3dSketcher, basicTbId ); //rnc
1155   createTool( GEOMOp::OpPlane,      basicTbId );
1156   createTool( GEOMOp::OpLCS,        basicTbId );
1157   createTool( GEOMOp::OpOriginAndVectors, basicTbId );
1158
1159 //   int sketchTbId = createTool( tr( "TOOL_SKETCH" ) );
1160 //   createTool( GEOMOp::Op2dSketcher,  sketchTbId );
1161 //   createTool( GEOMOp::Op3dSketcher,  sketchTbId );
1162
1163   int primTbId = createTool( tr( "TOOL_PRIMITIVES" ) );
1164   createTool( GEOMOp::OpBox,        primTbId );
1165   createTool( GEOMOp::OpCylinder,   primTbId );
1166   createTool( GEOMOp::OpSphere,     primTbId );
1167   createTool( GEOMOp::OpTorus,      primTbId );
1168   createTool( GEOMOp::OpCone,       primTbId );
1169   createTool( GEOMOp::OpRectangle,  primTbId );
1170   createTool( GEOMOp::OpDisk,       primTbId );
1171   createTool( GEOMOp::OpPipeTShape, primTbId ); //rnc
1172
1173   int blocksTbId = createTool( tr( "TOOL_BLOCKS" ) );
1174   createTool( GEOMOp::OpDividedDisk, blocksTbId );
1175   createTool( GEOMOp::OpDividedCylinder, blocksTbId );
1176
1177 //   int advancedTbId = createTool( tr( "TOOL_ADVANCED" ) ); //rnc
1178 //   createTool( GEOMOp::OpPipeTShape, advancedTbId );
1179
1180   int boolTbId = createTool( tr( "TOOL_BOOLEAN" ) );
1181   createTool( GEOMOp::OpFuse,       boolTbId );
1182   createTool( GEOMOp::OpCommon,     boolTbId );
1183   createTool( GEOMOp::OpCut,        boolTbId );
1184   createTool( GEOMOp::OpSection,    boolTbId );
1185
1186   int genTbId = createTool( tr( "TOOL_GENERATION" ) );
1187   createTool( GEOMOp::OpPrism,      genTbId );
1188   createTool( GEOMOp::OpRevolution, genTbId );
1189   createTool( GEOMOp::OpFilling,    genTbId );
1190   createTool( GEOMOp::OpPipe,       genTbId );
1191 #if OCC_VERSION_LARGE > 0x06050300
1192   createTool( GEOMOp::OpPipePath,   genTbId );
1193 #endif
1194
1195   int transTbId = createTool( tr( "TOOL_TRANSFORMATION" ) );
1196   createTool( GEOMOp::OpTranslate,      transTbId );
1197   createTool( GEOMOp::OpRotate,         transTbId );
1198   createTool( GEOMOp::OpChangeLoc,      transTbId );
1199   createTool( GEOMOp::OpMirror,         transTbId );
1200   createTool( GEOMOp::OpScale,          transTbId );
1201   createTool( GEOMOp::OpOffset,         transTbId );
1202   createTool( GEOMOp::OpProjection,     transTbId );
1203   createTool( separator(),              transTbId );
1204   createTool( GEOMOp::OpMultiTranslate, transTbId );
1205   createTool( GEOMOp::OpMultiRotate,    transTbId );
1206
1207   int operTbId = createTool( tr( "TOOL_OPERATIONS" ) );
1208   createTool( GEOMOp::OpExplode,         operTbId );
1209   createTool( GEOMOp::OpPartition,       operTbId );
1210   createTool( GEOMOp::OpArchimede,       operTbId );
1211   createTool( GEOMOp::OpShapesOnShape,   operTbId );
1212   createTool( GEOMOp::OpSharedShapes,    operTbId );
1213
1214   int featTbId = createTool( tr( "TOOL_FEATURES" ) );
1215   createTool( GEOMOp::OpFillet1d,        featTbId );
1216   createTool( GEOMOp::OpFillet2d,        featTbId );
1217   createTool( GEOMOp::OpFillet3d,        featTbId );
1218   createTool( GEOMOp::OpChamfer,         featTbId );
1219   createTool( GEOMOp::OpExtrudedBoss,    featTbId );
1220   createTool( GEOMOp::OpExtrudedCut,     featTbId );
1221
1222   int buildTbId = createTool( tr( "TOOL_BUILD" ) );
1223   createTool( GEOMOp::OpEdge,     buildTbId );
1224   createTool( GEOMOp::OpWire,     buildTbId );
1225   createTool( GEOMOp::OpFace,     buildTbId );
1226   createTool( GEOMOp::OpShell,    buildTbId );
1227   createTool( GEOMOp::OpSolid,    buildTbId );
1228   createTool( GEOMOp::OpCompound, buildTbId );
1229
1230   int measureTbId = createTool( tr( "TOOL_MEASURES" ) );
1231   createTool( GEOMOp::OpPointCoordinates, measureTbId );
1232   createTool( GEOMOp::OpProperties,       measureTbId );
1233   createTool( GEOMOp::OpCenterMass,       measureTbId );
1234   createTool( GEOMOp::OpInertia,          measureTbId );
1235   createTool( GEOMOp::OpNormale,          measureTbId );
1236   createTool( separator(),                measureTbId );
1237   createTool( GEOMOp::OpBoundingBox,      measureTbId );
1238   createTool( GEOMOp::OpMinDistance,      measureTbId );
1239   createTool( GEOMOp::OpAngle,            measureTbId );
1240   createTool( GEOMOp::OpTolerance  ,      measureTbId );
1241   createTool( separator(),                measureTbId );
1242   createTool( GEOMOp::OpFreeBoundaries,   measureTbId );
1243   createTool( GEOMOp::OpFreeFaces,        measureTbId );
1244   createTool( separator(),                measureTbId );
1245   createTool( GEOMOp::OpWhatIs,           measureTbId );
1246   createTool( GEOMOp::OpCheckShape,       measureTbId );
1247   createTool( GEOMOp::OpCheckCompound,    measureTbId );
1248   createTool( GEOMOp::OpGetNonBlocks,     measureTbId );
1249   createTool( GEOMOp::OpCheckSelfInters,  measureTbId );
1250
1251   int picturesTbId = createTool( tr( "TOOL_PICTURES" ) );
1252   createTool( GEOMOp::OpPictureImport,    picturesTbId );
1253   #ifdef WITH_OPENCV
1254     createTool( GEOMOp::OpFeatureDetect,  picturesTbId );
1255   #endif
1256
1257   int advancedTbId = createTool( tr( "TOOL_ADVANCED" ) );
1258   createTool( GEOMOp::OpSmoothingSurface, advancedTbId );
1259   //@@ 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 @@//
1260
1261   // ---- create popup menus --------------------------
1262
1263   QString clientOCCorVTK = "(client='OCCViewer' or client='VTKViewer')";
1264   QString clientOCC = "(client='OCCViewer')";
1265   QString clientOCCorVTK_AndSomeVisible = clientOCCorVTK + " and selcount>0 and isVisible";
1266   QString clientOCC_AndSomeVisible = clientOCC + " and selcount>0 and isVisible";
1267
1268   QString clientOCCorOB = "(client='ObjectBrowser' or client='OCCViewer')";
1269   QString clientOCCorVTKorOB = "(client='ObjectBrowser' or client='OCCViewer' or client='VTKViewer')";
1270   QString clientOCCorVTKorOB_AndSomeVisible = clientOCCorVTKorOB + " and selcount>0 and isVisible";
1271   QString clientOCCorOB_AndSomeVisible = clientOCCorOB + " and selcount>0 and isVisible";
1272
1273   QString autoColorPrefix =
1274     "(client='ObjectBrowser' or client='OCCViewer') and type='Shape' and selcount=1 and isOCC=true";
1275
1276   QtxPopupMgr* mgr = popupMgr();
1277
1278   mgr->insert( action(  GEOMOp::OpDelete ), -1, -1 );  // delete
1279   mgr->setRule( action( GEOMOp::OpDelete ), QString("$type in {'Shape' 'Group' 'Folder'} and selcount>0"), QtxPopupMgr::VisibleRule );
1280   mgr->insert( action(  GEOMOp::OpGroupCreatePopup ), -1, -1 ); // create group
1281   mgr->setRule( action( GEOMOp::OpGroupCreatePopup ), QString("type='Shape' and selcount=1 and isOCC=true"), QtxPopupMgr::VisibleRule );
1282   mgr->insert( action(  GEOMOp::OpDiscloseChildren ), -1, -1 ); // disclose child items
1283   mgr->setRule( action( GEOMOp::OpDiscloseChildren ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and hasConcealedChildren=true"), QtxPopupMgr::VisibleRule );
1284
1285   mgr->insert( action(  GEOMOp::OpConcealChildren ), -1, -1 ); // conceal shild items
1286   mgr->setRule( action( GEOMOp::OpConcealChildren ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and hasDisclosedChildren=true"), QtxPopupMgr::VisibleRule );
1287   mgr->insert( action(  GEOMOp::OpGroupEdit ), -1, -1 );  // edit group
1288   mgr->setRule( action( GEOMOp::OpGroupEdit ),  QString("client='ObjectBrowser' and type='Group' and selcount=1 and isOCC=true"), QtxPopupMgr::VisibleRule );
1289   mgr->insert( separator(), -1, -1 );     // -----------
1290
1291 #if OCC_VERSION_LARGE > 0x06050200
1292   //QString bringRule = clientOCCorOB + " and ($component={'GEOM'}) and (selcount>0) and isOCC=true and topLevel=false";
1293   QString bringRule = clientOCCorOB + " and ($component={'GEOM'}) and isFolder=false and (selcount>0) and isOCC=true";
1294   mgr->insert( action(GEOMOp::OpBringToFront ), -1, -1 ); // bring to front
1295   mgr->setRule(action(GEOMOp::OpBringToFront), bringRule + " and autoBringToFront = false", QtxPopupMgr::VisibleRule );
1296   mgr->setRule(action(GEOMOp::OpBringToFront), "topLevel=true", QtxPopupMgr::ToggleRule );
1297   mgr->insert( action(GEOMOp::OpClsBringToFront ), -1, -1 ); // clear bring to front
1298   mgr->setRule( action(GEOMOp::OpClsBringToFront ), clientOCC + " and autoBringToFront = false", QtxPopupMgr::VisibleRule );
1299 #endif
1300   mgr->insert( separator(), -1, -1 );     // -----------
1301   dispmodeId = mgr->insert(  tr( "MEN_DISPLAY_MODE" ), -1, -1 ); // display mode menu
1302   mgr->insert( action(  GEOMOp::OpWireframe ), dispmodeId, -1 ); // wireframe
1303   mgr->setRule( action( GEOMOp::OpWireframe ), clientOCCorVTK_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1304   mgr->setRule( action( GEOMOp::OpWireframe ), clientOCCorVTK + " and displaymode='Wireframe'", QtxPopupMgr::ToggleRule );
1305   mgr->insert( action(  GEOMOp::OpShading ), dispmodeId, -1 ); // shading
1306   mgr->setRule( action( GEOMOp::OpShading ), clientOCCorVTK_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1307   mgr->setRule( action( GEOMOp::OpShading ), clientOCCorVTK + " and displaymode='Shading'", QtxPopupMgr::ToggleRule );
1308   mgr->insert( action(  GEOMOp::OpShadingWithEdges ), dispmodeId, -1 ); // shading with edges
1309   mgr->setRule( action( GEOMOp::OpShadingWithEdges ), clientOCCorVTK_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1310   mgr->setRule( action( GEOMOp::OpShadingWithEdges ), clientOCCorVTK + " and displaymode='ShadingWithEdges'", QtxPopupMgr::ToggleRule );
1311   mgr->insert( action(  GEOMOp::OpTexture ), dispmodeId, -1 ); // wireframe
1312   mgr->setRule( action( GEOMOp::OpTexture ), clientOCC_AndSomeVisible, QtxPopupMgr::VisibleRule );
1313   mgr->setRule( action( GEOMOp::OpTexture), clientOCC + " and displaymode='Texture'", QtxPopupMgr::ToggleRule );
1314   mgr->insert( separator(), dispmodeId, -1 );
1315   mgr->insert( action(  GEOMOp::OpVectors ), dispmodeId, -1 ); // vectors
1316   mgr->setRule( action( GEOMOp::OpVectors ), clientOCCorVTK_AndSomeVisible  + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1317   mgr->setRule( action( GEOMOp::OpVectors ), clientOCCorVTK + " and isVectorsMode", QtxPopupMgr::ToggleRule );
1318   mgr->insert( separator(), -1, -1 );     // -----------
1319   
1320   mgr->insert( action(  GEOMOp::OpColor ), -1, -1 ); // color
1321   mgr->setRule( action( GEOMOp::OpColor ), clientOCCorVTKorOB_AndSomeVisible + " and ($component={'GEOM'})" + "and isPhysicalMaterial=false", QtxPopupMgr::VisibleRule );
1322   mgr->insert( action(  GEOMOp::OpTransparency ), -1, -1 ); // transparency
1323   mgr->setRule( action( GEOMOp::OpTransparency ), clientOCCorVTK_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1324   mgr->insert( action(  GEOMOp::OpIsos ), -1, -1 ); // isos
1325   mgr->setRule( action( GEOMOp::OpIsos ), clientOCCorVTK_AndSomeVisible + " and selcount>0 and isVisible" + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1326   mgr->insert( action(  GEOMOp::OpDeflection ), -1, -1 ); // deflection
1327   mgr->setRule( action( GEOMOp::OpDeflection ), clientOCCorVTK_AndSomeVisible + " and selcount>0 and isVisible" + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1328   mgr->insert( action(  GEOMOp::OpPointMarker ), -1, -1 ); // point marker
1329   //mgr->setRule( action( GEOMOp::OpPointMarker ), QString( "selcount>0 and $typeid in {%1}" ).arg(GEOM_POINT ), QtxPopupMgr::VisibleRule );
1330   mgr->setRule( action( GEOMOp::OpPointMarker ), QString( "selcount>0 and ( $typeid in {%1} or compoundOfVertices=true ) " ).arg(GEOM::VERTEX).arg(GEOM::COMPOUND), QtxPopupMgr::VisibleRule );
1331   
1332   // material properties
1333   mgr->insert( action(  GEOMOp::OpMaterialProperties ), -1, -1 ); 
1334   mgr->setRule( action( GEOMOp::OpMaterialProperties ), clientOCCorVTK_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1335
1336  // texture
1337   mgr->insert( action(  GEOMOp::OpSetTexture ), -1, -1 );
1338   mgr->setRule( action( GEOMOp::OpSetTexture ), clientOCCorOB_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1339
1340   int lineW = mgr->insert(  tr( "MEN_LINE_WIDTH" ), -1, -1 ); // line width menu
1341   mgr->insert( action(  GEOMOp::OpEdgeWidth ), lineW, -1 ); // edge width
1342   mgr->setRule( action( GEOMOp::OpEdgeWidth ), clientOCCorVTK_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1343
1344   mgr->insert( action(  GEOMOp::OpIsosWidth ), lineW, -1 ); // isos width
1345   mgr->setRule( action( GEOMOp::OpIsosWidth ), clientOCCorVTK_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1346
1347   mgr->insert( separator(), -1, -1 );     // -----------
1348   mgr->insert( action(  GEOMOp::OpAutoColor ), -1, -1 ); // auto color
1349   mgr->setRule( action( GEOMOp::OpAutoColor ), autoColorPrefix + " and isAutoColor=false", QtxPopupMgr::VisibleRule );
1350   mgr->insert( action(  GEOMOp::OpNoAutoColor ), -1, -1 ); // disable auto color
1351   mgr->setRule( action( GEOMOp::OpNoAutoColor ), autoColorPrefix + " and isAutoColor=true", QtxPopupMgr::VisibleRule );
1352   mgr->insert( separator(), -1, -1 );     // -----------
1353
1354   QString canDisplay = "($component={'GEOM'}) and (selcount>0) and ({true} in $canBeDisplayed) ",
1355           onlyComponent = "((type='Component') and selcount=1)",
1356           rule = canDisplay + "and ((($type in {%1}) and( %2 )) or " + onlyComponent + ")",
1357           types = "'Shape' 'Group'";
1358
1359   mgr->insert( action(  GEOMOp::OpShow ), -1, -1 ); // display
1360   mgr->setRule( action( GEOMOp::OpShow ), rule.arg( types ).arg( "not isVisible" ), QtxPopupMgr::VisibleRule );
1361
1362   mgr->insert( action(  GEOMOp::OpHide ), -1, -1 ); // erase
1363   mgr->setRule( action( GEOMOp::OpHide ), rule.arg( types ).arg( "isVisible" ), QtxPopupMgr::VisibleRule );
1364
1365   mgr->insert( action(  GEOMOp::OpHideAll ), -1, -1 ); // erase All
1366   mgr->setRule( action( GEOMOp::OpHideAll ), clientOCCorVTK, QtxPopupMgr::VisibleRule );
1367
1368   QString selectOnly = "(client='OCCViewer' or client='VTKViewer') and (selcount=0)";
1369
1370   int selectonlyId = mgr->insert( tr("MEN_SELECT_ONLY"), -1, -1);                //select only menu
1371   mgr->insert( action(GEOMOp::OpSelectVertex),   selectonlyId, -1);                                  //Vertex
1372   mgr->setRule(action(GEOMOp::OpSelectVertex),   selectOnly, QtxPopupMgr::VisibleRule);
1373   mgr->setRule(action(GEOMOp::OpSelectVertex),   selectOnly + " and selectionmode='VERTEX'", QtxPopupMgr::ToggleRule);
1374   mgr->insert( action(GEOMOp::OpSelectEdge),     selectonlyId, -1);                                  //Edge
1375   mgr->setRule(action(GEOMOp::OpSelectEdge),     selectOnly, QtxPopupMgr::VisibleRule);
1376   mgr->setRule(action(GEOMOp::OpSelectEdge),     selectOnly + " and selectionmode='EDGE'", QtxPopupMgr::ToggleRule);
1377   mgr->insert( action(GEOMOp::OpSelectWire),     selectonlyId, -1);                                  //Wire
1378   mgr->setRule(action(GEOMOp::OpSelectWire),     selectOnly, QtxPopupMgr::VisibleRule);
1379   mgr->setRule(action(GEOMOp::OpSelectWire),     selectOnly + " and selectionmode='WIRE'", QtxPopupMgr::ToggleRule);
1380   mgr->insert( action(GEOMOp::OpSelectFace),     selectonlyId, -1);                                  //Face
1381   mgr->setRule(action(GEOMOp::OpSelectFace),     selectOnly, QtxPopupMgr::VisibleRule);
1382   mgr->setRule(action(GEOMOp::OpSelectFace),     selectOnly + " and selectionmode='FACE'", QtxPopupMgr::ToggleRule);
1383   mgr->insert( action(GEOMOp::OpSelectShell),    selectonlyId, -1);                                  //Shell
1384   mgr->setRule(action(GEOMOp::OpSelectShell),    selectOnly, QtxPopupMgr::VisibleRule);
1385   mgr->setRule(action(GEOMOp::OpSelectShell),    selectOnly + " and selectionmode='SHELL'", QtxPopupMgr::ToggleRule);
1386   mgr->insert( action(GEOMOp::OpSelectSolid),    selectonlyId, -1);                                  //Solid
1387   mgr->setRule(action(GEOMOp::OpSelectSolid),    selectOnly, QtxPopupMgr::VisibleRule);
1388   mgr->setRule(action(GEOMOp::OpSelectSolid),    selectOnly + " and selectionmode='SOLID'", QtxPopupMgr::ToggleRule);
1389   mgr->insert( action(GEOMOp::OpSelectCompound), selectonlyId, -1);                                  //Compound
1390   mgr->setRule(action(GEOMOp::OpSelectCompound), selectOnly, QtxPopupMgr::VisibleRule);
1391   mgr->setRule(action(GEOMOp::OpSelectCompound), selectOnly + " and selectionmode='COMPOUND'", QtxPopupMgr::ToggleRule);
1392   mgr->insert( separator(), selectonlyId, -1);
1393   mgr->insert( action(GEOMOp::OpSelectAll),      selectonlyId, -1);                                  //Clear selection filter
1394   mgr->setRule(action(GEOMOp::OpSelectAll),      selectOnly, QtxPopupMgr::VisibleRule);
1395   mgr->setRule(action(GEOMOp::OpSelectAll),      selectOnly + " and selectionmode='ALL'", QtxPopupMgr::ToggleRule);
1396   mgr->insert( action(GEOMOp::OpShowOnly ), -1, -1 ); // display only
1397   mgr->setRule(action(GEOMOp::OpShowOnly ), rule.arg( types ).arg( "true" ), QtxPopupMgr::VisibleRule );
1398   mgr->insert( action(GEOMOp::OpShowOnlyChildren ), -1, -1 ); // display only children
1399   mgr->setRule(action(GEOMOp::OpShowOnlyChildren ), (canDisplay + "and ($type in {%1}) and client='ObjectBrowser' and hasChildren=true").arg( types ), QtxPopupMgr::VisibleRule );
1400
1401   mgr->insert( separator(), -1, -1 );     // -----------
1402   mgr->insert( action(  GEOMOp::OpUnpublishObject ), -1, -1 ); // Unpublish object
1403   mgr->setRule( action( GEOMOp::OpUnpublishObject ), QString("client='ObjectBrowser' and $type in {'Shape' 'Group'} and selcount>0"), QtxPopupMgr::VisibleRule );
1404
1405   mgr->insert( action(  GEOMOp::OpPublishObject ), -1, -1 ); // Publish object
1406   mgr->setRule( action( GEOMOp::OpPublishObject ), QString("client='ObjectBrowser' and isComponent=true"), QtxPopupMgr::VisibleRule );
1407
1408   mgr->insert( action(  GEOMOp::OpReimport ), -1, -1 );  // delete
1409   mgr->setRule( action( GEOMOp::OpReimport ), QString("$imported in {'true'} and selcount>0"), QtxPopupMgr::VisibleRule );
1410
1411   mgr->insert( separator(), -1, -1 );     // -----------
1412   mgr->insert( action(  GEOMOp::OpCreateFolder ), -1, -1 ); // Create Folder
1413   mgr->setRule( action( GEOMOp::OpCreateFolder ), QString("client='ObjectBrowser' and $component={'GEOM'} and (isComponent=true or isFolder=true)"), QtxPopupMgr::VisibleRule );
1414
1415   mgr->insert( separator(), -1, -1 );     // -----------
1416   mgr->insert( action(  GEOMOp::OpSortChildren ), -1, -1 ); // Sort child items
1417   mgr->setRule( action( GEOMOp::OpSortChildren ), QString("client='ObjectBrowser' and $component={'GEOM'} and nbChildren>1"), QtxPopupMgr::VisibleRule );
1418
1419   mgr->hide( mgr->actionId( action( myEraseAll ) ) );
1420
1421   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1422   if (resMgr) {
1423     GEOM_AISShape::setTopLevelDisplayMode((GEOM_AISShape::TopLevelDispMode)resMgr->integerValue("Geometry", "toplevel_dm", 0));
1424     QColor c = resMgr->colorValue( "Geometry", "toplevel_color", QColor( 170, 85, 0 ) );
1425     GEOM_AISShape::setTopLevelColor(SalomeApp_Tools::color(c));
1426   }
1427 }
1428
1429 //=======================================================================
1430 // function : GeometryGUI::activateModule()
1431 // purpose  : Called when GEOM module is activated
1432 //=======================================================================
1433 bool GeometryGUI::activateModule( SUIT_Study* study )
1434 {
1435   if ( CORBA::is_nil( myComponentGeom ) )
1436     return false;
1437
1438   bool res = SalomeApp_Module::activateModule( study );
1439
1440   if ( !res )
1441     return false;
1442   setMenuShown( true );
1443   setToolShown( true );
1444
1445   // import Python module that manages GEOM plugins (need to be here because SalomePyQt API uses active module)
1446   PyGILState_STATE gstate = PyGILState_Ensure();
1447   PyObject* pluginsmanager = PyImport_ImportModuleNoBlock((char*)"salome_pluginsmanager");
1448   if (pluginsmanager == NULL)
1449     PyErr_Print();
1450   else {
1451     PyObject* result =
1452       PyObject_CallMethod(pluginsmanager, (char*)"initialize", (char*)"isss", 1, "geom",
1453                           tr("MEN_NEW_ENTITY").toStdString().c_str(),
1454                           tr("GEOM_PLUGINS_OTHER").toStdString().c_str());
1455     if (result == NULL)
1456       PyErr_Print();
1457     Py_XDECREF(result);
1458   }
1459   PyGILState_Release(gstate);
1460   // end of GEOM plugins loading
1461
1462   connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1463           this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1464
1465   // Reset actions accelerator keys
1466   action(GEOMOp::OpImport)->setEnabled( true ); // Import: CTRL + Key_I
1467   action(GEOMOp::OpExport)->setEnabled( true ); // Export: CTRL + Key_E
1468   action(GEOMOp::OpDelete)->setEnabled( true ); // Delete: Key_Delete
1469
1470   GUIMap::Iterator it;
1471   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1472     it.value()->activate( application()->desktop() );
1473
1474   LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1475
1476   connect( sm, SIGNAL( currentSelectionChanged() ), this, SLOT( updateCreationInfo() ));
1477   connect( sm, SIGNAL( currentSelectionChanged() ), this, SLOT( onAutoBringToFront() ));
1478
1479   if ( !myCreationInfoWdg )
1480     myCreationInfoWdg = new GEOMGUI_CreationInfoWdg( getApp() );
1481   getApp()->insertDockWindow( myCreationInfoWdg->getWinID(), myCreationInfoWdg );
1482   getApp()->placeDockWindow( myCreationInfoWdg->getWinID(), Qt::LeftDockWidgetArea );
1483
1484   SUIT_ViewManager* vm;
1485   ViewManagerList OCCViewManagers, VTKViewManagers;
1486
1487   application()->viewManagers( OCCViewer_Viewer::Type(), OCCViewManagers );
1488   QListIterator<SUIT_ViewManager*> itOCC( OCCViewManagers );
1489   while ( itOCC.hasNext() && (vm = itOCC.next()) )
1490     myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1491
1492   application()->viewManagers( SVTK_Viewer::Type(), VTKViewManagers );
1493   QListIterator<SUIT_ViewManager*> itVTK( VTKViewManagers );
1494   while ( itVTK.hasNext() && (vm = itVTK.next()) )
1495     myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
1496
1497   //NPAL 19674
1498   SALOME_ListIO selected;
1499   sm->selectedObjects( selected );
1500   sm->clearSelected();
1501
1502   // disable OCC selectors
1503   getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1504   QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1505   while ( itOCCSel.hasNext() )
1506     if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1507       sr->setEnabled(true);
1508
1509   // disable VTK selectors
1510   getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
1511   QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1512   while ( itVTKSel.hasNext() )
1513     if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1514       sr->setEnabled(true);
1515
1516   sm->setSelectedObjects( selected, true );   //NPAL 19674
1517
1518   QMenu* viewMenu = menuMgr()->findMenu( STD_Application::MenuViewId );
1519   if ( viewMenu )
1520     connect( viewMenu, SIGNAL( aboutToShow() ), this, SLOT( onViewAboutToShow() ) );
1521
1522   // 0020836 (Basic vectors and origin)
1523   SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
1524   if ( aResourceMgr->booleanValue( "Geometry", "auto_create_base_objects", false ) ) {
1525     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
1526     if ( appStudy ) {
1527       _PTR(Study) studyDS = appStudy->studyDS();
1528       if ( studyDS ) {
1529         _PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
1530         if ( !aSComponent ) // create objects automatically only if there is no GEOM component
1531           createOriginAndBaseVectors();
1532       }
1533     }
1534   }
1535
1536   return true;
1537 }
1538
1539 //=======================================================================
1540 // function : GeometryGUI::deactivateModule()
1541 // purpose  : Called when GEOM module is deactivated
1542 //=======================================================================
1543 bool GeometryGUI::deactivateModule( SUIT_Study* study )
1544 {
1545   QMenu* viewMenu = menuMgr()->findMenu( STD_Application::MenuViewId );
1546   if ( viewMenu )
1547     disconnect( viewMenu, SIGNAL( aboutToShow() ), this, SLOT( onViewAboutToShow() ) );
1548
1549   setMenuShown( false );
1550   setToolShown( false );
1551
1552   disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1553              this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1554
1555   LightApp_SelectionMgr* selMrg = getApp()->selectionMgr();
1556
1557   disconnect( selMrg, SIGNAL( currentSelectionChanged() ), this, SLOT( updateCreationInfo() ));
1558   getApp()->removeDockWindow( myCreationInfoWdg->getWinID() );
1559   myCreationInfoWdg = 0;
1560
1561   EmitSignalCloseAllDialogs();
1562
1563   GUIMap::Iterator it;
1564   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1565     it.value()->deactivate();
1566
1567   // Unset actions accelerator keys
1568   action(GEOMOp::OpImport)->setEnabled( false ); // Import: CTRL + Key_I
1569   action(GEOMOp::OpExport)->setEnabled( false ); // Export: CTRL + Key_E
1570   action(GEOMOp::OpDelete)->setEnabled( false ); // Delete: Key_Delete
1571
1572   qDeleteAll(myOCCSelectors);
1573   myOCCSelectors.clear();
1574   selMrg->setEnabled( true, OCCViewer_Viewer::Type() );
1575
1576   qDeleteAll(myVTKSelectors);
1577   myVTKSelectors.clear();
1578   selMrg->setEnabled( true, SVTK_Viewer::Type() );
1579
1580   return SalomeApp_Module::deactivateModule( study );
1581 }
1582
1583 //=======================================================================
1584 // function : onWindowActivated()
1585 // purpose  : update menu items' status - disable non-OCC-viewer-compatible actions
1586 //=======================================================================
1587 void GeometryGUI::onWindowActivated( SUIT_ViewWindow* win )
1588 {
1589   if ( !win )
1590     return;
1591
1592   const bool ViewOCC = ( win->getViewManager()->getType() == OCCViewer_Viewer::Type() );
1593   //const bool ViewVTK = ( win->getViewManager()->getType() == SVTK_Viewer::Type() );
1594
1595   // disable non-OCC viewframe menu commands
1596 //  action( GEOMOp::Op2dSketcher )->setEnabled( ViewOCC ); // SKETCHER
1597   action( GEOMOp::OpSuppressFaces )->setEnabled( ViewOCC ); // SuppressFace
1598   action( GEOMOp::OpSuppressHoles )->setEnabled( ViewOCC ); // SuppressHole
1599   action( GEOMOp::OpCloseContour )->setEnabled( ViewOCC ); // CloseContour
1600   action( GEOMOp::OpRemoveIntWires )->setEnabled( ViewOCC ); // RemoveInternalWires
1601   action( GEOMOp::OpAddPointOnEdge )->setEnabled( ViewOCC ); // AddPointOnEdge
1602 //  action( GEOMOp::OpFreeBoundaries )->setEnabled( ViewOCC ); // Free boundaries
1603
1604   action( GEOMOp::OpGroupCreate )->setEnabled( ViewOCC ); // Create Group
1605   action( GEOMOp::OpGroupEdit )->setEnabled( ViewOCC ); // Edit Group
1606
1607   action( GEOMOp::OpMultiTransform )->setEnabled( ViewOCC ); // MENU BLOCKS - MULTI-TRANSFORMATION
1608 }
1609
1610 void GeometryGUI::windows( QMap<int, int>& mappa ) const
1611 {
1612   mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
1613   mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
1614   if ( myCreationInfoWdg )
1615     mappa.insert( myCreationInfoWdg->getWinID(), Qt::LeftDockWidgetArea );
1616 }
1617
1618 void GeometryGUI::viewManagers( QStringList& lst ) const
1619 {
1620   lst.append( OCCViewer_Viewer::Type() );
1621 }
1622
1623 void GeometryGUI::onViewManagerAdded( SUIT_ViewManager* vm )
1624 {
1625   if ( vm && vm->getType() == OCCViewer_Viewer::Type() )
1626   {
1627     qDebug( "connect" );
1628     connect( vm, SIGNAL( keyPress  ( SUIT_ViewWindow*, QKeyEvent* ) ),
1629              this, SLOT( OnKeyPress( SUIT_ViewWindow*, QKeyEvent* ) ) );
1630     connect( vm, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
1631              this, SLOT( OnMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
1632     connect( vm, SIGNAL( mouseMove ( SUIT_ViewWindow*, QMouseEvent* ) ),
1633              this, SLOT( OnMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1634     connect( vm, SIGNAL( mouseRelease ( SUIT_ViewWindow*, QMouseEvent* ) ),
1635              this, SLOT( OnMouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ) );
1636
1637     LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1638     myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1639
1640     // disable OCC selectors
1641     getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1642     QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1643     while ( itOCCSel.hasNext() )
1644       if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1645         sr->setEnabled(true);
1646   }
1647   else if ( vm->getType() == SVTK_Viewer::Type() )
1648   {
1649     LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1650     myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
1651
1652     // disable VTK selectors
1653     getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
1654     QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1655     while ( itVTKSel.hasNext() )
1656       if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1657         sr->setEnabled(true);
1658   }
1659 }
1660
1661 void GeometryGUI::onViewManagerRemoved( SUIT_ViewManager* vm )
1662 {
1663   SUIT_ViewModel* viewer = vm->getViewModel();
1664   if ( vm->getType() == OCCViewer_Viewer::Type() )
1665   {
1666     QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1667     while ( itOCCSel.hasNext() )
1668       if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1669         if ( sr->viewer() == viewer )
1670         {
1671           /*delete*/ myOCCSelectors.takeAt( myOCCSelectors.indexOf( sr ) );
1672           break;
1673         }
1674   }
1675   if ( vm->getType() == SVTK_Viewer::Type() )
1676   {
1677     QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1678     while ( itVTKSel.hasNext() )
1679       if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1680         if ( sr->viewer() == viewer )
1681         {
1682           /*delete*/ myVTKSelectors.takeAt( myVTKSelectors.indexOf( sr ) );
1683           break;
1684         }
1685   }
1686 }
1687
1688 //================================================================================
1689 /*!
1690  * \brief Slot called when selection changed. Shows creation info of a selected object 
1691  */
1692 //================================================================================
1693
1694 void GeometryGUI::updateCreationInfo()
1695 {
1696   myCreationInfoWdg->clear();
1697
1698   // Code below is commented to have myCreationInfoWdg filled as soon as it is shown again
1699   // if ( !myCreationInfoWdg->isVisible() )
1700   //   return;
1701
1702   // look for a sole selected GEOM_Object
1703   GEOM::GEOM_Object_var geomObj;
1704
1705   SALOME_ListIO selected;
1706   getApp()->selectionMgr()->selectedObjects( selected );
1707
1708   _PTR(Study) study = dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() )->studyDS();
1709   SALOME_ListIteratorOfListIO selIt( selected );
1710   for ( ; selIt.More(); selIt.Next() )
1711   {
1712     Handle(SALOME_InteractiveObject) io = selIt.Value();
1713     if ( !io->hasEntry() ) continue;
1714     _PTR(SObject) sobj = study->FindObjectID( io->getEntry() );
1715     if ( !sobj ) continue;
1716     CORBA::Object_var      obj = GeometryGUI::ClientSObjectToObject( sobj );
1717     GEOM::GEOM_Object_var gobj = GEOM::GEOM_Object::_narrow( obj );
1718     if ( !gobj->_is_nil() )
1719     {
1720       if ( !geomObj->_is_nil() )
1721         return; // several GEOM objects selected
1722       geomObj = gobj;
1723     }
1724   }
1725   if ( geomObj->_is_nil() ) return;
1726
1727   // pass creation info of geomObj to myCreationInfoWdg
1728
1729   QPixmap icon;
1730   QString operationName;
1731   myCreationInfoWdg->setOperation( icon, operationName );
1732
1733   try
1734   {
1735     OCC_CATCH_SIGNALS;
1736     GEOM::CreationInformation_var info = geomObj->GetCreationInformation();
1737     if ( &info.in() )
1738     {
1739       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1740       QString name = info->operationName.in();
1741       if ( !name.isEmpty() )
1742       {
1743         icon = resMgr->loadPixmap( "GEOM", tr( ("ICO_"+name).toLatin1().constData() ), false );
1744         operationName = tr( ("MEN_"+name).toLatin1().constData() );
1745         if ( operationName.startsWith( "MEN_" ))
1746           operationName = name; // no translation
1747         myCreationInfoWdg->setOperation( icon, operationName );
1748
1749         for ( size_t i = 0; i < info->params.length(); ++i )
1750           myCreationInfoWdg->addParam( info->params[i].name.in(),
1751                                        info->params[i].value.in() );
1752       }
1753     }
1754   }
1755   catch (...)
1756   {
1757   }
1758 }
1759
1760 void GeometryGUI::onAutoBringToFront()
1761 {
1762   bool isAutoBringToFront = SUIT_Session::session()->resourceMgr()->booleanValue( "Geometry", "auto_bring_to_front" );
1763   if( !isAutoBringToFront )
1764     return;
1765
1766   SUIT_ViewWindow* SUIT_window = application()->desktop()->activeWindow();
1767   if ( !SUIT_window || SUIT_window->getViewManager()->getType() != OCCViewer_Viewer::Type() )
1768         return;
1769
1770   SalomeApp_Study* appStudy = dynamic_cast< SalomeApp_Study* >( getApp()->activeStudy() );
1771   if (!appStudy) return;
1772
1773   GEOM_Displayer displayer( appStudy );
1774
1775   SALOME_View* window = displayer.GetActiveView();
1776   if ( !window ) return;
1777
1778   int aMgrId = dynamic_cast< SUIT_ViewModel* >( window )->getViewManager()->getGlobalId();
1779
1780   SALOME_ListIO selected;
1781   getApp()->selectionMgr()->selectedObjects( selected );
1782   SALOME_ListIO allObjects;
1783   window->GetVisible( allObjects );
1784
1785   for ( SALOME_ListIteratorOfListIO It( allObjects ); It.More(); It.Next() ) {
1786     Handle( SALOME_InteractiveObject ) io = It.Value();
1787     bool isSelected = false;
1788     for( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
1789       Handle( SALOME_InteractiveObject ) ioSelected = It.Value();
1790       if( io->isSame( ioSelected ) )
1791         isSelected = true;
1792     }
1793     QVariant v = appStudy->getObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::TopLevel ), QVariant() );
1794     bool isTopLevel =  v.isValid() ? v.toBool() : false;
1795     if( isSelected && !isTopLevel ) {
1796       appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::TopLevel ), true );
1797       if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
1798     }
1799     else if( !isSelected ) {
1800       appStudy->setObjectProperty( aMgrId, io->getEntry(), GEOM::propertyName( GEOM::TopLevel ), false );
1801       if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
1802     }
1803   }
1804   displayer.UpdateViewer();
1805   GeometryGUI::Modified();
1806 }
1807
1808 QString GeometryGUI::engineIOR() const
1809 {
1810   if ( !CORBA::is_nil( GetGeomGen() ) )
1811     return QString( getApp()->orb()->object_to_string( GetGeomGen() ) );
1812   return "";
1813 }
1814
1815 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
1816 Handle(TColStd_HArray1OfByte) GeometryGUI::getTexture
1817 #else
1818 Handle(Graphic3d_HArray1OfBytes) GeometryGUI::getTexture
1819 #endif
1820       (SalomeApp_Study* theStudy, int theId, int& theWidth, int& theHeight)
1821 {
1822   theWidth = theHeight = 0;
1823
1824 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
1825   Handle(TColStd_HArray1OfByte) aTexture;
1826 #else
1827   Handle(Graphic3d_HArray1OfBytes) aTexture;
1828 #endif
1829
1830   if (theStudy) {
1831     TextureMap aTextureMap = myTextureMap[ theStudy->studyDS()->StudyId() ];
1832     aTexture = aTextureMap[ theId ];
1833     if ( aTexture.IsNull() ) {
1834       GEOM::GEOM_IInsertOperations_var aInsOp = GeometryGUI::GetGeomGen()->GetIInsertOperations( theStudy->studyDS()->StudyId() );
1835       if ( !aInsOp->_is_nil() ) {
1836         CORBA::Long aWidth, aHeight;
1837         SALOMEDS::TMPFile_var aStream = aInsOp->GetTexture( theId, aWidth, aHeight );
1838         if ( aWidth > 0 && aHeight > 0 && aStream->length() > 0 ) {
1839           theWidth  = aWidth;
1840           theHeight = aHeight;
1841
1842 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
1843           aTexture  = new TColStd_HArray1OfByte (1, aStream->length());
1844 #else
1845           aTexture  = new Graphic3d_HArray1OfBytes (1, aStream->length());
1846 #endif
1847
1848           for (int i = 0; i < aStream->length(); i++)
1849             aTexture->SetValue( i+1, (Standard_Byte)aStream[i] );
1850           aTextureMap[ theId ] = aTexture;
1851         }
1852       }
1853     }
1854   }
1855   return aTexture;
1856 }
1857
1858 LightApp_Selection* GeometryGUI::createSelection() const
1859 {
1860   return new GEOMGUI_Selection();
1861 }
1862
1863 void GeometryGUI::contextMenuPopup( const QString& client, QMenu* menu, QString& title )
1864 {
1865   SalomeApp_Module::contextMenuPopup( client, menu, title );
1866   SALOME_ListIO lst;
1867   getApp()->selectionMgr()->selectedObjects( lst );
1868
1869   //Add submenu for predefined materials
1870   bool isPredefMat = SUIT_Session::session()->resourceMgr()->booleanValue( "Geometry", "predef_materials" );
1871   if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() > 0 ) {
1872     QtxPopupMgr* mgr = popupMgr();
1873     //get parrent for submenu
1874     QAction* act = mgr->action( mgr->actionId( action(  GEOMOp::OpMaterialProperties ) ) );
1875     //Clear old  menu
1876     QMenu* oldMenu = act->menu() ;
1877     if( oldMenu ) {
1878       delete oldMenu;
1879     }
1880     if( isPredefMat ){
1881       QMenu* matMenu = new QMenu();
1882       QSignalMapper* signalMapper = new QSignalMapper( matMenu );
1883       
1884       //Get current material model for the object
1885       QVariant v;
1886       LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( getApp() );
1887       if ( anApp && anApp->activeViewManager() ) {
1888         LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( anApp->activeStudy() );
1889         if( aStudy ) {
1890           v = aStudy->getObjectProperty( anApp->activeViewManager()->getGlobalId(), lst.Last()->getEntry(), GEOM::propertyName( GEOM::Material ), QVariant() );
1891         }
1892       }
1893       QString curModel = "";
1894       if ( v.canConvert<QString>() ) curModel = v.toString();
1895       // get list of all predefined materials
1896       QStringList materials = Material_ResourceMgr::resourceMgr()->materials();
1897       bool found = false;
1898       foreach ( QString material, materials ) 
1899       {
1900         QAction* menAct = matMenu->addAction( material );
1901         connect(menAct, SIGNAL( toggled( bool ) ), signalMapper, SLOT( map() ) );
1902         signalMapper->setMapping( menAct, material );
1903         menAct->setCheckable( true );
1904         // Set checked if this material is current 
1905         Material_Model aModel;
1906         aModel.fromResources( material );
1907         if ( !found && aModel.toProperties() == curModel ) {
1908           menAct->setChecked( true );
1909           found = true;
1910         }
1911       }
1912       matMenu->insertAction( matMenu->addSeparator(), action(  GEOMOp::OpPredefMaterCustom ) );
1913       matMenu->insertSeparator( action(  GEOMOp::OpPredefMaterCustom ) );
1914       connect( signalMapper, SIGNAL( mapped( const QString & ) ),
1915                  this, SLOT( OnSetMaterial( const QString & ) ) );
1916       act->setMenu( matMenu );
1917     }
1918   }
1919   //Set name
1920   if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
1921     Handle(SALOME_InteractiveObject) io = lst.First();
1922     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
1923     _PTR(Study) study = appStudy->studyDS();
1924     _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
1925     if ( obj ) {
1926       QString aName = QString( obj->GetName().c_str() );
1927       aName.remove( QRegExp("\\s+$") );
1928       title = aName;
1929     }
1930   }
1931 }
1932
1933 void GeometryGUI::OnSetMaterial(const QString& theName)
1934 {
1935   OnGUIEvent( GEOMOp::OpPredefMaterial, QVariant( theName ) );
1936 }
1937
1938
1939 void GeometryGUI::createPreferences()
1940 {
1941   int tabId = addPreference( tr( "PREF_TAB_SETTINGS" ) );
1942
1943   int genGroup = addPreference( tr( "PREF_GROUP_GENERAL" ), tabId );
1944   setPreferenceProperty( genGroup, "columns", 2 );
1945
1946   int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), genGroup,
1947                                 LightApp_Preferences::Selector,
1948                                 "Geometry", "display_mode" );
1949
1950   addPreference( tr( "PREF_SHADING_COLOR" ), genGroup,
1951                  LightApp_Preferences::Color, "Geometry", "shading_color" );
1952
1953   addPreference( tr( "PREF_EDGES_IN_SHADING" ), genGroup,
1954                  LightApp_Preferences::Color, "Geometry", "edges_in_shading_color" );
1955
1956   addPreference( tr( "PREF_WIREFRAME_COLOR" ), genGroup,
1957                  LightApp_Preferences::Color, "Geometry", "wireframe_color" );
1958
1959   addPreference( tr( "PREF_FREE_BOUND_COLOR" ), genGroup,
1960                  LightApp_Preferences::Color, "Geometry", "free_bound_color" );
1961
1962   addPreference( tr( "PREF_LINE_COLOR"), genGroup,
1963                  LightApp_Preferences::Color, "Geometry", "line_color" );
1964
1965   addPreference( tr( "PREF_POINT_COLOR"), genGroup,
1966                  LightApp_Preferences::Color, "Geometry", "point_color" );
1967
1968   addPreference( tr( "PREF_ISOS_COLOR" ), genGroup,
1969                  LightApp_Preferences::Color, "Geometry", "isos_color" );
1970
1971   addPreference( tr( "PREF_TOPLEVEL_COLOR" ), genGroup,
1972                  LightApp_Preferences::Color, "Geometry", "toplevel_color" );
1973
1974   int top_lev_dm = addPreference( tr( "PREF_TOPLEVEL_DM" ), genGroup,
1975                       LightApp_Preferences::Selector, "Geometry", "toplevel_dm" );
1976
1977   int step = addPreference( tr( "PREF_STEP_VALUE" ), genGroup,
1978                             LightApp_Preferences::IntSpin, "Geometry", "SettingsGeomStep" );
1979
1980   int defl = addPreference( tr( "PREF_DEFLECTION" ), genGroup,
1981                             LightApp_Preferences::DblSpin, "Geometry", "deflection_coeff" );
1982
1983   addPreference( tr( "PREF_PREDEF_MATERIALS" ), genGroup,
1984                  LightApp_Preferences::Bool, "Geometry", "predef_materials" );
1985
1986   int material = addPreference( tr( "PREF_MATERIAL" ), genGroup,
1987                                 LightApp_Preferences::Selector,
1988                                 "Geometry", "material" );
1989
1990   addPreference( tr( "PREF_EDITGROUP_COLOR" ), genGroup,
1991                  LightApp_Preferences::Color, "Geometry", "editgroup_color" );
1992
1993   const int nb = 4;
1994   int wd[nb];
1995   int iter=0;
1996
1997   wd[iter++] = addPreference( tr( "PREF_EDGE_WIDTH" ), genGroup,
1998                               LightApp_Preferences::IntSpin, "Geometry", "edge_width" );
1999
2000   wd[iter++] = addPreference( tr( "PREF_ISOLINES_WIDTH" ), genGroup,
2001                               LightApp_Preferences::IntSpin, "Geometry", "isolines_width" );
2002
2003   wd[iter++] = addPreference( tr( "PREF_PREVIEW_EDGE_WIDTH" ), genGroup,
2004                                      LightApp_Preferences::IntSpin, "Geometry", "preview_edge_width" );
2005
2006   wd[iter++] = addPreference( tr( "PREF_MEASURES_LINE_WIDTH" ), genGroup,
2007                               LightApp_Preferences::IntSpin, "Geometry", "measures_line_width" );
2008
2009   for (int i = 0; i < nb; i++) {
2010     setPreferenceProperty( wd[i], "min", 1 );
2011     setPreferenceProperty( wd[i], "max", 5 );
2012   }
2013
2014   addPreference( tr( "PREF_AUTO_BRING_TO_FRONT" ), genGroup,
2015                  LightApp_Preferences::Bool, "Geometry", "auto_bring_to_front" );
2016  
2017   int isoGroup = addPreference( tr( "PREF_ISOS" ), tabId );
2018   setPreferenceProperty( isoGroup, "columns", 2 );
2019   int isoU = addPreference( tr( "PREF_ISOS_U" ), isoGroup,
2020                                   LightApp_Preferences::IntSpin, "Geometry", "iso_number_u" );
2021   setPreferenceProperty( isoU, "min", 0 );
2022   setPreferenceProperty( isoU, "max", 100000 );
2023   int isoV = addPreference( tr( "PREF_ISOS_V" ), isoGroup,
2024                                  LightApp_Preferences::IntSpin, "Geometry", "iso_number_v" );
2025   setPreferenceProperty( isoV, "min", 0 );
2026   setPreferenceProperty( isoV, "max", 100000 );
2027
2028   // Quantities with individual precision settings
2029   int precGroup = addPreference( tr( "GEOM_PREF_GROUP_PRECISION" ), tabId );
2030   setPreferenceProperty( precGroup, "columns", 2 );
2031
2032   const int nbQuantities = 8;
2033   int prec[nbQuantities], ii = 0;
2034   prec[ii++] = addPreference( tr( "GEOM_PREF_length_precision" ), precGroup,
2035                               LightApp_Preferences::IntSpin, "Geometry", "length_precision" );
2036   prec[ii++] = addPreference( tr( "GEOM_PREF_angle_precision" ), precGroup,
2037                               LightApp_Preferences::IntSpin, "Geometry", "angle_precision" );
2038   prec[ii++] = addPreference( tr( "GEOM_PREF_len_tol_precision" ), precGroup,
2039                               LightApp_Preferences::IntSpin, "Geometry", "len_tol_precision" );
2040   prec[ii++] = addPreference( tr( "GEOM_PREF_ang_tol_precision" ), precGroup,
2041                               LightApp_Preferences::IntSpin, "Geometry", "ang_tol_precision" );
2042   prec[ii++] = addPreference( tr( "GEOM_PREF_weight_precision" ), precGroup,
2043                               LightApp_Preferences::IntSpin, "Geometry", "weight_precision" );
2044   prec[ii++] = addPreference( tr( "GEOM_PREF_density_precision" ), precGroup,
2045                               LightApp_Preferences::IntSpin, "Geometry", "density_precision" );
2046   prec[ii++] = addPreference( tr( "GEOM_PREF_parametric_precision" ), precGroup,
2047                               LightApp_Preferences::IntSpin, "Geometry", "parametric_precision" );
2048   prec[ii  ] = addPreference( tr( "GEOM_PREF_param_tol_precision" ), precGroup,
2049                               LightApp_Preferences::IntSpin, "Geometry", "param_tol_precision" );
2050
2051   // Set property for precision value for spinboxes
2052   for ( ii = 0; ii < nbQuantities; ii++ ){
2053     setPreferenceProperty( prec[ii], "min", -14 );
2054     setPreferenceProperty( prec[ii], "max", 14 );
2055     setPreferenceProperty( prec[ii], "precision", 2 );
2056   }
2057
2058   int VertexGroup = addPreference( tr( "PREF_GROUP_VERTEX" ), tabId );
2059   setPreferenceProperty( VertexGroup, "columns", 2 );
2060
2061   int typeOfMarker = addPreference( tr( "PREF_TYPE_OF_MARKER" ), VertexGroup,
2062                                     LightApp_Preferences::Selector, "Geometry", "type_of_marker" );
2063
2064   int markerScale = addPreference( tr( "PREF_MARKER_SCALE" ), VertexGroup,
2065                                    LightApp_Preferences::Selector, "Geometry", "marker_scale" );
2066
2067   // Set property for default display mode
2068   QStringList aModesList;
2069   aModesList.append( tr("MEN_WIREFRAME") );
2070   aModesList.append( tr("MEN_SHADING") );
2071   aModesList.append( tr("MEN_SHADING_WITH_EDGES") );
2072
2073   QList<QVariant> anIndexesList;
2074   anIndexesList.append(0);
2075   anIndexesList.append(1);
2076   anIndexesList.append(2);
2077
2078   setPreferenceProperty( dispmode, "strings", aModesList );
2079   setPreferenceProperty( dispmode, "indexes", anIndexesList );
2080
2081   // Set property for top level display mode
2082   QStringList aTopModesList;
2083   aTopModesList.append( tr("MEN_SHOW_ADD_WACTOR") );
2084   aTopModesList.append( tr("MEN_KEEP_CURRENT_DM") );
2085   aTopModesList.append( tr("MEN_WIREFRAME") );
2086   aTopModesList.append( tr("MEN_SHADING") );
2087   aTopModesList.append( tr("MEN_SHADING_WITH_EDGES") );
2088
2089   QList<QVariant> aTopIndexesList;
2090   aTopIndexesList.append(0);
2091   aTopIndexesList.append(1);
2092   aTopIndexesList.append(2);
2093   aTopIndexesList.append(3);
2094   aTopIndexesList.append(4);
2095
2096   setPreferenceProperty( top_lev_dm, "strings", aTopModesList );
2097   setPreferenceProperty( top_lev_dm, "indexes", aTopIndexesList );
2098
2099   // Set property for step value for spinboxes
2100   setPreferenceProperty( step, "min", 1 );
2101   setPreferenceProperty( step, "max", 10000 );
2102   setPreferenceProperty( step, "precision", 3 );
2103
2104   // Set property for deflection value for spinboxes
2105   setPreferenceProperty( defl, "min", GEOM::minDeflection() );
2106   setPreferenceProperty( defl, "max", 1.0 );
2107   setPreferenceProperty( defl, "step", 1.0e-04 );
2108   setPreferenceProperty( defl, "precision", 6 );
2109
2110   // Set property for default material
2111   setPreferenceProperty( material, "strings", Material_ResourceMgr::resourceMgr()->materials() );
2112   
2113   // Set property vertex marker type
2114   QList<QVariant> aMarkerTypeIndicesList;
2115   QList<QVariant> aMarkerTypeIconsList;
2116
2117   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2118   for ( int i = GEOM::MT_POINT; i < GEOM::MT_USER; i++ ) {
2119     QString icoFile = QString( "ICON_VERTEX_MARKER_%1" ).arg( i );
2120     QPixmap pixmap = resMgr->loadPixmap( "GEOM", tr( qPrintable( icoFile ) ) );
2121     aMarkerTypeIndicesList << (i-1);
2122     aMarkerTypeIconsList << pixmap;
2123   }
2124
2125   setPreferenceProperty( typeOfMarker, "indexes", aMarkerTypeIndicesList );
2126   setPreferenceProperty( typeOfMarker, "icons",   aMarkerTypeIconsList );
2127
2128   // Set property for vertex marker scale
2129   QList<QVariant> aMarkerScaleIndicesList;
2130   QStringList     aMarkerScaleValuesList;
2131
2132   for ( int iii = GEOM::MS_10; iii <= GEOM::MS_70; iii++ ) {
2133     aMarkerScaleIndicesList << iii;
2134     aMarkerScaleValuesList  << QString::number( (iii-(int)GEOM::MS_10)*0.5 + 1.0 );
2135   }
2136
2137   setPreferenceProperty( markerScale, "strings", aMarkerScaleValuesList );
2138   setPreferenceProperty( markerScale, "indexes", aMarkerScaleIndicesList );
2139
2140   int originGroup = addPreference( tr( "PREF_GROUP_ORIGIN_AND_BASE_VECTORS" ), tabId );
2141   setPreferenceProperty( originGroup, "columns", 2 );
2142
2143   int baseVectorsLength = addPreference( tr( "PREF_BASE_VECTORS_LENGTH" ), originGroup,
2144                                          LightApp_Preferences::DblSpin, "Geometry", "base_vectors_length" );
2145   setPreferenceProperty( baseVectorsLength, "min", 0.01 );
2146   setPreferenceProperty( baseVectorsLength, "max", 1000 );
2147
2148   addPreference( tr( "PREF_AUTO_CREATE" ), originGroup,
2149                  LightApp_Preferences::Bool, "Geometry", "auto_create_base_objects" );
2150
2151   int operationsGroup = addPreference( tr( "PREF_GROUP_OPERATIONS" ), tabId );
2152   setPreferenceProperty( operationsGroup, "columns", 2 );
2153
2154   addPreference( tr( "GEOM_PREVIEW" ), operationsGroup,
2155                  LightApp_Preferences::Bool, "Geometry", "geom_preview" );
2156 }
2157
2158 void GeometryGUI::preferencesChanged( const QString& section, const QString& param )
2159 {
2160   if (section == "Geometry") {
2161     SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
2162     if (param == QString("SettingsGeomStep")) {
2163       double spin_step = aResourceMgr->doubleValue(section, param, 100.);
2164       EmitSignalDefaultStepValueChanged(spin_step);
2165     }
2166     else if (param == QString("toplevel_color")) {
2167       QColor c = aResourceMgr->colorValue( "Geometry", "toplevel_color", QColor( 170, 85, 0 ) );
2168       GEOM_AISShape::setTopLevelColor(SalomeApp_Tools::color(c));
2169     }
2170     else if (param == QString("toplevel_dm")) {
2171       GEOM_AISShape::setTopLevelDisplayMode((GEOM_AISShape::TopLevelDispMode)aResourceMgr->integerValue("Geometry", "toplevel_dm", 0));
2172     }
2173   }
2174 }
2175
2176 LightApp_Displayer* GeometryGUI::displayer()
2177 {
2178   if ( !myDisplayer )
2179     myDisplayer = new GEOM_Displayer( dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) );
2180   return myDisplayer;
2181 }
2182
2183 void GeometryGUI::setLocalSelectionMode(const int mode)
2184 {
2185   myLocalSelectionMode = mode;
2186 }
2187
2188 int GeometryGUI::getLocalSelectionMode() const
2189 {
2190   return myLocalSelectionMode;
2191 }
2192
2193 const char gSeparator = '_'; // character used to separate parameter names
2194 const char gDigitsSep = ':'; // character used to separate numeric parameter values (color = r:g:b)
2195
2196 /*!
2197  * \brief Store visual parameters
2198  *
2199  * This method is called just before the study document is saved.
2200  * Store visual parameters in AttributeParameter attribute(s)
2201  */
2202 void GeometryGUI::storeVisualParameters (int savePoint)
2203 {
2204   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
2205   if ( !appStudy || !appStudy->studyDS() )
2206     return;
2207   _PTR(Study) studyDS = appStudy->studyDS();
2208
2209   // componentName is used for encoding of entries when storing them in IParameters
2210   std::string componentName = myComponentGeom->ComponentDataType();
2211   //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
2212   //if (!aSComponent) return;
2213
2214   // IParameters
2215   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
2216                                                              componentName.c_str(),
2217                                                              savePoint);
2218   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
2219
2220   QList<SUIT_ViewManager*> lst;
2221   QList<SUIT_ViewManager*>::Iterator it;
2222
2223   // main cycle to store parameters of displayed objects
2224   lst.clear();
2225   getApp()->viewManagers(lst);
2226   for (it = lst.begin(); it != lst.end(); it++) {
2227     SUIT_ViewManager* vman = *it;
2228     QString vType = vman->getType();
2229     int aMgrId = vman->getGlobalId();
2230     // saving VTK actors properties
2231     QVector<SUIT_ViewWindow*> views = vman->getViews();
2232     for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++) {
2233       const ObjMap anObjects = appStudy->getObjectMap(aMgrId);
2234       ObjMap::ConstIterator o_it = anObjects.begin();
2235       for (; o_it != anObjects.end(); o_it++) {
2236         const PropMap aProps = o_it.value();
2237
2238         //Check that object exists in the study
2239         _PTR(SObject) obj( studyDS->FindObjectID( o_it.key().toLatin1().data() ) );
2240         if ( !obj || !(aProps.count() > 0))
2241           continue;
2242         // entry is "encoded" = it does NOT contain component adress, since it is a
2243         // subject to change on next component loading
2244
2245         std::string entry = ip->encodeEntry(o_it.key().toLatin1().data(), componentName);
2246
2247         _PTR(GenericAttribute) anAttr;
2248         if (!obj->FindAttribute(anAttr, "AttributeIOR"))
2249           continue;
2250
2251         QString param, occParam = vType;
2252         occParam += GEOM::sectionSeparator();
2253         occParam += QString::number(aMgrId);
2254         occParam += GEOM::sectionSeparator();
2255
2256         if (aProps.contains(GEOM::propertyName( GEOM::Visibility ))) {
2257           param = occParam + GEOM::propertyName( GEOM::Visibility );
2258           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::Visibility )).toBool() ? "On" : "Off");
2259         }
2260
2261         if (aProps.contains(GEOM::propertyName( GEOM::DisplayMode ))) {
2262           param = occParam + GEOM::propertyName( GEOM::DisplayMode );
2263           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::DisplayMode )).toString().toStdString());
2264         }
2265
2266         if (aProps.contains(GEOM::propertyName( GEOM::Color ))) {
2267           QColor c = aProps.value(GEOM::propertyName( GEOM::Color )).value<QColor>();
2268           QStringList val;
2269           val << QString::number(c.redF());
2270           val << QString::number(c.greenF());
2271           val << QString::number(c.blueF());
2272           param = occParam + GEOM::propertyName( GEOM::Color );
2273           ip->setParameter(entry, param.toStdString(), val.join( GEOM::subSectionSeparator()).toStdString());
2274         }
2275
2276         if (vType == SVTK_Viewer::Type()) {
2277           if (aProps.contains(GEOM::propertyName( GEOM::Opacity ))) {
2278             param = occParam + GEOM::propertyName( GEOM::Opacity );
2279             ip->setParameter(entry, param.toStdString(), QString::number(1. - aProps.value(GEOM::propertyName( GEOM::Transparency )).toDouble()).toStdString());
2280           }
2281         } else if (vType == SOCC_Viewer::Type()) {
2282           if (aProps.contains(GEOM::propertyName( GEOM::Transparency ))) {
2283             param = occParam + GEOM::propertyName( GEOM::Transparency );
2284             ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::Transparency )).toString().toStdString());
2285           }
2286
2287           if (aProps.contains(GEOM::propertyName( GEOM::TopLevel ))) {
2288             param = occParam + GEOM::propertyName( GEOM::TopLevel );
2289             ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::TopLevel )).toString().toStdString());
2290           }
2291         }
2292
2293         if (aProps.contains(GEOM::propertyName( GEOM::NbIsos ))) {
2294           param = occParam + GEOM::propertyName( GEOM::NbIsos );
2295           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::NbIsos )).toString().toStdString());
2296         }
2297
2298         if (aProps.contains(GEOM::propertyName( GEOM::EdgesDirection ))) {
2299           param = occParam + GEOM::propertyName( GEOM::EdgesDirection );
2300           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::EdgesDirection )).toString().toStdString());
2301         }
2302
2303         if (aProps.contains(GEOM::propertyName( GEOM::Deflection ))) {
2304           param = occParam + GEOM::propertyName( GEOM::Deflection );
2305           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::Deflection )).toString().toStdString());
2306         }
2307
2308         //Marker type of the vertex - ONLY for the "Vertex" and "Compound of the Vertex"
2309         if (aProps.contains(GEOM::propertyName( GEOM::PointMarker ))) {
2310           param = occParam + GEOM::propertyName( GEOM::PointMarker );
2311           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::PointMarker )).toString().toStdString());
2312         }
2313
2314         if (aProps.contains(GEOM::propertyName( GEOM::Material ))) {
2315           param = occParam + GEOM::propertyName( GEOM::Material );
2316           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::Material )).toString().toStdString());
2317         }
2318
2319         if (aProps.contains(GEOM::propertyName( GEOM::LineWidth ))) {
2320              param = occParam + GEOM::propertyName( GEOM::LineWidth );
2321            ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::LineWidth )).toString().toStdString());
2322         }
2323
2324         if (aProps.contains(GEOM::propertyName( GEOM::IsosWidth ))) {
2325           param = occParam + GEOM::propertyName( GEOM::IsosWidth );
2326           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::IsosWidth )).toString().toStdString());
2327         }
2328       } // object iterator
2329     } // for (views)
2330   } // for (viewManagers)
2331 }
2332
2333 /*!
2334  * \brief Restore visual parameters
2335  *
2336  * This method is called after the study document is opened.
2337  * Restore visual parameters from AttributeParameter attribute(s)
2338  */
2339 void GeometryGUI::restoreVisualParameters (int savePoint)
2340 {
2341   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
2342   if (!appStudy || !appStudy->studyDS())
2343     return;
2344   _PTR(Study) studyDS = appStudy->studyDS();
2345
2346   // componentName is used for encoding of entries when storing them in IParameters
2347   std::string componentName = myComponentGeom->ComponentDataType();
2348   //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
2349   //if (!aSComponent) return;
2350
2351   // IParameters
2352   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
2353                                                              componentName.c_str(),
2354                                                              savePoint);
2355   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
2356
2357   std::vector<std::string> entries = ip->getEntries();
2358
2359   for (std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt)
2360   {
2361     // entry is a normal entry - it should be "decoded" (setting base adress of component)
2362     QString entry (ip->decodeEntry(*entIt).c_str());
2363
2364     // Check that the entry corresponds to a real object in the Study
2365     // as the object may be deleted or modified after the visual state is saved.
2366     _PTR(SObject) so = studyDS->FindObjectID(entry.toLatin1().data());
2367     if (!so) continue; //Skip the not existent entry
2368
2369     std::vector<std::string> paramNames = ip->getAllParameterNames( *entIt );
2370     std::vector<std::string> paramValues = ip->getAllParameterValues( *entIt );
2371
2372     std::vector<std::string>::iterator namesIt = paramNames.begin();
2373     std::vector<std::string>::iterator valuesIt = paramValues.begin();
2374
2375     // actors are stored in a map after displaying of them for
2376     // quicker access in the future: map < viewID to actor >
2377     NCollection_DataMap<int, GEOM_Actor*          > vtkActors;
2378     NCollection_DataMap<int, Handle(GEOM_AISShape)> occActors;
2379
2380     QString viewerTypStr;
2381     QString viewIndexStr;
2382     int viewIndex;
2383     QVector<PropMap> aListOfMap;
2384
2385     for (; namesIt != paramNames.end(); ++namesIt, ++valuesIt)
2386     {
2387       // visual parameters are stored in strings as follows: ViewerType_ViewIndex_ParamName.
2388       // '_' is used as separator and should not be used in viewer type or parameter names.
2389       QStringList lst = QString((*namesIt).c_str()).split( GEOM::sectionSeparator(), QString::SkipEmptyParts);
2390       if (lst.size() != 3)
2391         continue;
2392
2393       viewerTypStr = lst[0];
2394       viewIndexStr = lst[1];
2395       QString paramNameStr = lst[2];
2396
2397       bool ok;
2398       viewIndex = viewIndexStr.toUInt(&ok);
2399       if (!ok) // bad conversion of view index to integer
2400         continue;
2401
2402       if ((viewIndex + 1) > aListOfMap.count()) {
2403         aListOfMap.resize(viewIndex + 1);
2404       }
2405
2406       QString val((*valuesIt).c_str());
2407       if (paramNameStr == GEOM::propertyName( GEOM::Visibility )) {
2408         aListOfMap[viewIndex].insert(GEOM::propertyName( GEOM::Visibility ), val == "On");
2409       } else if (paramNameStr == GEOM::propertyName( GEOM::Opacity )) {
2410         aListOfMap[viewIndex].insert(GEOM::propertyName( GEOM::Transparency ), 1. - val.toDouble());
2411       } else if (paramNameStr == GEOM::propertyName( GEOM::Transparency )) {
2412         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::Transparency ), val.toDouble() );
2413       } else if (paramNameStr == GEOM::propertyName( GEOM::TopLevel )) {
2414         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::TopLevel ), val == "true" || val == "1");
2415       } else if (paramNameStr == GEOM::propertyName( GEOM::DisplayMode )) {
2416         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::DisplayMode ), val.toInt());
2417       } else if (paramNameStr == GEOM::propertyName( GEOM::NbIsos )) {
2418         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::NbIsos ), val);
2419       } else if (paramNameStr == GEOM::propertyName( GEOM::Color )) {
2420         QStringList rgb = val.split(GEOM::subSectionSeparator());
2421         if (rgb.count() == 3) {
2422           QColor c = QColor::fromRgbF(rgb[0].toDouble(), rgb[1].toDouble(), rgb[2].toDouble());
2423           aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::Color ), c);
2424         }
2425       } else if (paramNameStr == GEOM::propertyName( GEOM::EdgesDirection )) {
2426         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::EdgesDirection ), val == "true" || val == "1");
2427       } else if (paramNameStr == GEOM::propertyName( GEOM::Deflection )) {
2428         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::Deflection ), val.toDouble());
2429       } else if (paramNameStr == GEOM::propertyName( GEOM::PointMarker )) {
2430         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::PointMarker ), val);
2431       } else if (paramNameStr == GEOM::propertyName( GEOM::Material )) {
2432         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::Material ), val);
2433       } else if (paramNameStr == GEOM::propertyName( GEOM::LineWidth )) {
2434         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::LineWidth ), val.toInt());
2435       } else if (paramNameStr == GEOM::propertyName( GEOM::IsosWidth )) {
2436         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::IsosWidth ), val.toInt());
2437       }
2438     } // for names/parameters iterator
2439
2440     QList<SUIT_ViewManager*> lst = getApp()->viewManagers();
2441
2442     for (int index = 0; index < aListOfMap.count(); index++) {
2443
2444       appStudy->setObjectPropMap(index, entry, aListOfMap[index]);
2445
2446       //Get Visibility property of the current PropMap
2447       if (aListOfMap[index].value(GEOM::propertyName( GEOM::Visibility )) == 1) {
2448         SUIT_ViewManager* vman = lst.at(index);
2449         SUIT_ViewModel* vmodel = vman->getViewModel();
2450         displayer()->Display(entry, true, dynamic_cast<SALOME_View*>(vmodel));
2451       }
2452     }
2453   } // for entries iterator
2454
2455   // update all VTK and OCC views
2456   QList<SUIT_ViewManager*> lst;
2457   getApp()->viewManagers(lst);
2458   for (QList<SUIT_ViewManager*>::Iterator it = lst.begin(); it != lst.end(); it++) {
2459     SUIT_ViewModel* vmodel = (*it)->getViewModel();
2460     if (!vmodel)
2461       continue;
2462     if (vmodel->getType() == SVTK_Viewer::Type()) {
2463       SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) (*it)->getActiveView();
2464       vtkView->getRenderer()->ResetCameraClippingRange();
2465       vtkView->Repaint();
2466     }
2467     else if (vmodel->getType() == SOCC_Viewer::Type()) {
2468       //SOCC_ViewWindow* occView = (SOCC_ViewWindow*) (*it)->getActiveView();
2469       SALOME_View* occVMod = dynamic_cast<SALOME_View*>(vmodel);
2470       if (occVMod)
2471         occVMod->Repaint();
2472     }
2473   }
2474 }
2475
2476 void GeometryGUI::onViewAboutToShow()
2477 {
2478   SUIT_ViewWindow* window = application()->desktop()->activeWindow();
2479   QAction* a = action( GEOMOp::OpSwitchVectors );
2480   if ( window ) {
2481     a->setEnabled(true);
2482     bool vmode = window->property("VectorsMode").toBool();
2483     a->setText ( vmode == 1 ? tr( "MEN_VECTOR_MODE_OFF" ) : tr("MEN_VECTOR_MODE_ON") );
2484   } else {
2485     a->setText ( tr("MEN_VECTOR_MODE_ON") );
2486     a->setEnabled(false);
2487   }
2488 }
2489
2490 /*!
2491   \brief Return action by id
2492   \param id identifier of the action
2493   \return action
2494 */
2495 QAction* GeometryGUI::getAction(const int id) {
2496   return action(id);
2497 }
2498
2499 /*!
2500   \brief GEOM module message handler
2501
2502   This method can be re-implemented in the subclasses.
2503   This is a GEOM module message handler.
2504
2505   \param msg the message received.
2506 */
2507 void GeometryGUI::message(const QString& msg)
2508 {
2509   // dispatch message
2510   QStringList data = msg.split("/");
2511   const int nbStrings = data.count();
2512
2513   if (nbStrings > 0) {
2514     if (data[0] == "modified") {
2515       // get mesh entry
2516       QString anIOR = nbStrings > 1 ? data[1] : QString();
2517
2518       if ( anIOR.isEmpty() ) {
2519         return;
2520       }
2521
2522       // Get the geom object.
2523       GEOM::GEOM_Object_ptr anObj = GeometryGUI::GetObjectFromIOR (anIOR);
2524
2525       // Clear the shape buffer
2526       GeometryGUI::ClearShapeBuffer (anObj);
2527     }
2528   }
2529 }
2530
2531 /*!
2532   \brief Clears the shape buffer.
2533
2534   This is a static method. It clears the shape buffer.
2535
2536   \param theObj the object
2537 */
2538 void GeometryGUI::ClearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
2539 {
2540   if ( CORBA::is_nil( theObj ) )
2541     return;
2542
2543   CORBA::String_var IOR = SalomeApp_Application::orb()->object_to_string( theObj );
2544   TCollection_AsciiString asciiIOR( (char *)IOR.in() );
2545   GEOM_Client::get_client().RemoveShapeFromBuffer( asciiIOR );
2546
2547   SALOMEDSClient_StudyManager *aManager = SalomeApp_Application::studyMgr();
2548
2549   if (!aManager)
2550     return;
2551
2552   _PTR(Study) aStudy = aManager->GetStudyByID(theObj->GetStudyID());
2553
2554   if ( !aStudy )
2555     return;
2556
2557   _PTR(SObject) aSObj ( aStudy->FindObjectIOR( std::string( IOR ) ) );
2558   if ( !aSObj )
2559     return;
2560
2561   _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
2562   for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
2563     _PTR(GenericAttribute) anAttr;
2564     if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) {
2565       _PTR(AttributeIOR) anIOR ( anAttr );
2566       TCollection_AsciiString asciiIOR( (char*)anIOR->Value().c_str() );
2567       GEOM_Client::get_client().RemoveShapeFromBuffer( asciiIOR );
2568     }
2569   }
2570 }
2571
2572 /*!
2573   \brief Returns the object from IOR.
2574
2575   This is a static method. It returns the object from its IOR.
2576
2577   \param IOR object IOR
2578   \return GEOM object.
2579 */
2580 GEOM::GEOM_Object_ptr GeometryGUI::GetObjectFromIOR( const QString& IOR )
2581 {
2582   GEOM::GEOM_Object_var geomObj;
2583   if ( !IOR.isEmpty() ) {
2584     CORBA::Object_var corbaObj = SalomeApp_Application::orb()->string_to_object
2585       ( IOR.toLatin1().constData() );
2586     if ( !CORBA::is_nil( corbaObj ) )
2587       geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
2588   }
2589   return geomObj._retn();
2590 }
2591
2592 /*!
2593   \brief Returns IOR of the object.
2594
2595   This is a static method. It returns the object's IOR.
2596
2597   \param object the GEOM object.
2598   \return object's IOR.
2599 */
2600 QString GeometryGUI::GetIORFromObject( GEOM::GEOM_Object_ptr object )
2601 {
2602   QString IOR;
2603   if ( !CORBA::is_nil( object ) ) {
2604     CORBA::String_var anIOR =
2605       SalomeApp_Application::orb()->object_to_string( object );
2606     IOR = anIOR.in();
2607   }
2608   return IOR;
2609 }
2610
2611 /*!
2612   \brief Check if this object is can't be renamed in place
2613
2614   This method can be re-implemented in the subclasses.
2615   Return true in case if object isn't reference or component (module root).
2616
2617   \param entry column id
2618   \return \c true if the item can be renamed by the user in place (e.g. in the Object browser)
2619 */
2620 bool GeometryGUI::renameAllowed( const QString& entry) const {
2621
2622   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2623   SalomeApp_Study* appStudy = app ? dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) : 0;
2624   SalomeApp_DataObject* obj = appStudy ? dynamic_cast<SalomeApp_DataObject*>(appStudy->findObjectByEntry(entry)) : 0;
2625
2626   return (app && appStudy && obj && !appStudy->isComponent(entry) && !obj->isReference());
2627 }
2628
2629 /*!
2630   Rename object by entry.
2631   \param entry entry of the object
2632   \param name new name of the object
2633   \brief Return \c true if rename operation finished successfully, \c false otherwise.
2634 */
2635 bool GeometryGUI::renameObject( const QString& entry, const QString& name)
2636 {
2637   bool result = false;
2638
2639   SalomeApp_Application* app =
2640     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication());
2641   SalomeApp_Study* appStudy = app ? dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) : 0;
2642
2643   if (!appStudy)
2644     return result;
2645
2646   _PTR(Study) aStudy = appStudy->studyDS();
2647
2648   if (!aStudy)
2649     return result;
2650
2651   bool aLocked = (_PTR(AttributeStudyProperties)(appStudy->studyDS()->GetProperties()))->IsLocked();
2652   if ( aLocked ) {
2653     SUIT_MessageBox::warning ( app->desktop(), QObject::tr("WRN_WARNING"), QObject::tr("WRN_STUDY_LOCKED") );
2654     return result;
2655   }
2656
2657   _PTR(SObject) obj ( aStudy->FindObjectID(qPrintable(entry)) );
2658   _PTR(GenericAttribute) anAttr;
2659   if ( obj ) {
2660     if ( obj->FindAttribute(anAttr, "AttributeName") ) {
2661       _PTR(AttributeName) aName (anAttr);
2662
2663       aName->SetValue( name.toLatin1().data() ); // rename the SObject
2664       GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(obj));
2665       if (!CORBA::is_nil(anObj)) {
2666         anObj->SetName( name.toLatin1().data() );  // Rename the corresponding GEOM_Object
2667       }
2668       result = true;
2669     }
2670   }
2671   return result;
2672 }
2673
2674 void GeometryGUI::updateMaterials()
2675 {
2676   LightApp_Preferences* pref = preferences();
2677   if ( pref ) {
2678     QStringList materials = Material_ResourceMgr::resourceMgr()->materials();
2679     QString currentMaterial = SUIT_Session::session()->resourceMgr()->stringValue( "Geometry", "material" );
2680     if ( !materials.contains( currentMaterial ) )
2681       // user material set as default in the preferences, might be removed
2682       SUIT_Session::session()->resourceMgr()->setValue( "Geometry", "material", QString( "Plastic" ) );
2683
2684     QtxPreferenceItem* prefItem = pref->rootItem()->findItem( tr( "PREF_MATERIAL" ), true );
2685     if ( prefItem ) {
2686       setPreferenceProperty( prefItem->id(),
2687                              "strings", materials );
2688       prefItem->retrieve();
2689     }
2690   }
2691 }
2692
2693 /*!
2694   \brief Check if the module allows "drag" operation of its objects.
2695
2696   Overloaded from LightApp_Module class.
2697   
2698   This function is a part of the general drag-n-drop mechanism.
2699   The goal of this function is to check data object passed as a parameter
2700   and decide if it can be dragged or no.
2701
2702   \param what data object being tested for drag operation
2703   \return \c true if module allows dragging of the specified object
2704   \sa isDropAccepted(), dropObjects()
2705 */
2706 bool GeometryGUI::isDraggable( const SUIT_DataObject* what ) const
2707 {
2708   // we allow dragging object under root and object from folder
2709   int aLevel = what->level();
2710   bool anObjectInFolder = false;
2711   if ( aLevel > 2 ) {
2712     const SalomeApp_DataObject* dataObj = dynamic_cast<const SalomeApp_DataObject*>( what );
2713     if ( dataObj ) {
2714       _PTR(SObject) aSO = dataObj->object();
2715       if ( aSO ) {
2716         _PTR(GenericAttribute) anAttr;
2717         _PTR(SObject) aFatherSO = aSO->GetStudy()->GetUseCaseBuilder()->GetFather( aSO );
2718         if ( aFatherSO && aFatherSO->FindAttribute(anAttr, "AttributeLocalID") ) {
2719           _PTR(AttributeLocalID) aLocalID( anAttr );
2720           anObjectInFolder = aLocalID->Value() == 999;
2721         }
2722       }
2723     }
2724   }
2725   return aLevel == 2 || anObjectInFolder;
2726 }
2727
2728 /*!
2729   \brief Check if the module allows "drop" operation on the given object.
2730
2731   Overloaded from LightApp_Module class.
2732
2733   This function is a part of the general drag-n-drop mechanism.
2734   The goal of this function is to check data object passed as a parameter
2735   and decide if it can be used as a target for the "drop" operation.
2736   The processing of the drop operation itself is done in the dropObjects() function.
2737
2738   \param where target data object
2739   \return \c true if module supports dropping on the \a where data object
2740   \sa isDraggable(), dropObjects()
2741 */
2742 bool GeometryGUI::isDropAccepted( const SUIT_DataObject* where ) const
2743 {
2744   // we allow dropping into folder and top-level GEOM object
2745   int aLevel = where->level();
2746   bool isFolder = false;
2747   if ( aLevel > 1 ) {
2748     const SalomeApp_DataObject* dataObj = dynamic_cast<const SalomeApp_DataObject*>( where );
2749     if ( dataObj ) {
2750       _PTR(SObject) aSO = dataObj->object();
2751       if ( aSO ) {
2752         _PTR(GenericAttribute) anAttr;
2753         if ( aSO->FindAttribute(anAttr, "AttributeLocalID") ) {
2754           _PTR(AttributeLocalID) aLocalID( anAttr );
2755           isFolder = aLocalID->Value() == 999;
2756         }
2757       }
2758     }
2759   }
2760   return aLevel == 1 || isFolder;
2761 }
2762
2763 /*!
2764   \brief Complete drag-n-drop operation.
2765   
2766   Overloaded from LightApp_Module class.
2767
2768   This function is a part of the general drag-n-drop mechanism.
2769   Its goal is to handle dropping of the objects being dragged according
2770   to the chosen operation (move). The dropping is performed in the
2771   context of the parent data object \a where and the \a row (position in the 
2772   children index) at which the data should be dropped. If \a row is equal to -1,
2773   this means that objects are added to the end of the children list.
2774
2775   \param what objects being dropped
2776   \param where target data object
2777   \param row child index at which the drop operation is performed
2778   \param action drag-n-drop operation (Qt::DropAction) - move
2779
2780   \sa isDraggable(), isDropAccepted()
2781 */
2782 void GeometryGUI::dropObjects( const DataObjectList& what, SUIT_DataObject* where,
2783                                const int row, Qt::DropAction action )
2784 {
2785   if (action != Qt::CopyAction && action != Qt::MoveAction)
2786     return; // unsupported action
2787
2788   // get parent object
2789   SalomeApp_DataObject* dataObj = dynamic_cast<SalomeApp_DataObject*>( where );
2790   if ( !dataObj ) return; // wrong parent
2791   _PTR(SObject) parentObj = dataObj->object();
2792
2793   // Find the current Study and StudyBuilder
2794   _PTR(Study) aStudy = parentObj->GetStudy();
2795   _PTR(UseCaseBuilder) aUseCaseBuilder = aStudy->GetUseCaseBuilder();
2796   // collect all parents of the target node
2797   QStringList parentIDs;
2798   _PTR(SObject) parent = parentObj;
2799   while( !parent->IsNull() ) {
2800     parentIDs << parent->GetID().c_str();
2801     parent = aUseCaseBuilder->GetFather(parent);
2802   }
2803
2804   // collect objects being dropped
2805   GEOM::object_list_var objects = new GEOM::object_list();
2806   objects->length( what.count() );
2807   int count = 0;
2808   for ( int i = 0; i < what.count(); i++ ) {
2809     dataObj = dynamic_cast<SalomeApp_DataObject*>( what[i] );
2810     if ( !dataObj ) continue;  // skip wrong objects
2811     _PTR(SObject) sobj = dataObj->object();
2812     // check that dropped object is not a parent of target object
2813     if ( parentIDs.contains( sobj->GetID().c_str() ) ) {
2814       return; // it's not allowed to move node into it's child 
2815     }
2816     objects[i] = _CAST(SObject, sobj)->GetSObject();
2817     count++;
2818   }
2819   objects->length( count );
2820
2821   // call engine function
2822   GetGeomGen()->Move( objects.in(),                              // what
2823                       _CAST(SObject, parentObj)->GetSObject(),   // where
2824                       row );                                     // row
2825
2826   // update Object browser
2827   getApp()->updateObjectBrowser( false );
2828 }