]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMGUI/GeometryGUI.cxx
Salome HOME
0021708: [CEA 586] Object browser sort only children:
[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, 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, 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   if ( !myCreationInfoWdg )
1478     myCreationInfoWdg = new GEOMGUI_CreationInfoWdg( getApp() );
1479   getApp()->insertDockWindow( myCreationInfoWdg->getWinID(), myCreationInfoWdg );
1480   getApp()->placeDockWindow( myCreationInfoWdg->getWinID(), Qt::LeftDockWidgetArea );
1481
1482   SUIT_ViewManager* vm;
1483   ViewManagerList OCCViewManagers, VTKViewManagers;
1484
1485   application()->viewManagers( OCCViewer_Viewer::Type(), OCCViewManagers );
1486   QListIterator<SUIT_ViewManager*> itOCC( OCCViewManagers );
1487   while ( itOCC.hasNext() && (vm = itOCC.next()) )
1488     myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1489
1490   application()->viewManagers( SVTK_Viewer::Type(), VTKViewManagers );
1491   QListIterator<SUIT_ViewManager*> itVTK( VTKViewManagers );
1492   while ( itVTK.hasNext() && (vm = itVTK.next()) )
1493     myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
1494
1495   //NPAL 19674
1496   SALOME_ListIO selected;
1497   sm->selectedObjects( selected );
1498   sm->clearSelected();
1499
1500   // disable OCC selectors
1501   getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1502   QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1503   while ( itOCCSel.hasNext() )
1504     if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1505       sr->setEnabled(true);
1506
1507   // disable VTK selectors
1508   getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
1509   QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1510   while ( itVTKSel.hasNext() )
1511     if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1512       sr->setEnabled(true);
1513
1514   sm->setSelectedObjects( selected, true );   //NPAL 19674
1515
1516   QMenu* viewMenu = menuMgr()->findMenu( STD_Application::MenuViewId );
1517   if ( viewMenu )
1518     connect( viewMenu, SIGNAL( aboutToShow() ), this, SLOT( onViewAboutToShow() ) );
1519
1520   // 0020836 (Basic vectors and origin)
1521   SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
1522   if ( aResourceMgr->booleanValue( "Geometry", "auto_create_base_objects", false ) ) {
1523     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
1524     if ( appStudy ) {
1525       _PTR(Study) studyDS = appStudy->studyDS();
1526       if ( studyDS ) {
1527         _PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
1528         if ( !aSComponent ) // create objects automatically only if there is no GEOM component
1529           createOriginAndBaseVectors();
1530       }
1531     }
1532   }
1533
1534   return true;
1535 }
1536
1537 //=======================================================================
1538 // function : GeometryGUI::deactivateModule()
1539 // purpose  : Called when GEOM module is deactivated
1540 //=======================================================================
1541 bool GeometryGUI::deactivateModule( SUIT_Study* study )
1542 {
1543   QMenu* viewMenu = menuMgr()->findMenu( STD_Application::MenuViewId );
1544   if ( viewMenu )
1545     disconnect( viewMenu, SIGNAL( aboutToShow() ), this, SLOT( onViewAboutToShow() ) );
1546
1547   setMenuShown( false );
1548   setToolShown( false );
1549
1550   disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1551              this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1552
1553   LightApp_SelectionMgr* selMrg = getApp()->selectionMgr();
1554
1555   disconnect( selMrg, SIGNAL( currentSelectionChanged() ), this, SLOT( updateCreationInfo() ));
1556   getApp()->removeDockWindow( myCreationInfoWdg->getWinID() );
1557   myCreationInfoWdg = 0;
1558
1559   EmitSignalCloseAllDialogs();
1560
1561   GUIMap::Iterator it;
1562   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1563     it.value()->deactivate();
1564
1565   // Unset actions accelerator keys
1566   action(GEOMOp::OpImport)->setEnabled( false ); // Import: CTRL + Key_I
1567   action(GEOMOp::OpExport)->setEnabled( false ); // Export: CTRL + Key_E
1568   action(GEOMOp::OpDelete)->setEnabled( false ); // Delete: Key_Delete
1569
1570   qDeleteAll(myOCCSelectors);
1571   myOCCSelectors.clear();
1572   selMrg->setEnabled( true, OCCViewer_Viewer::Type() );
1573
1574   qDeleteAll(myVTKSelectors);
1575   myVTKSelectors.clear();
1576   selMrg->setEnabled( true, SVTK_Viewer::Type() );
1577
1578   return SalomeApp_Module::deactivateModule( study );
1579 }
1580
1581 //=======================================================================
1582 // function : onWindowActivated()
1583 // purpose  : update menu items' status - disable non-OCC-viewer-compatible actions
1584 //=======================================================================
1585 void GeometryGUI::onWindowActivated( SUIT_ViewWindow* win )
1586 {
1587   if ( !win )
1588     return;
1589
1590   const bool ViewOCC = ( win->getViewManager()->getType() == OCCViewer_Viewer::Type() );
1591   //const bool ViewVTK = ( win->getViewManager()->getType() == SVTK_Viewer::Type() );
1592
1593   // disable non-OCC viewframe menu commands
1594 //  action( GEOMOp::Op2dSketcher )->setEnabled( ViewOCC ); // SKETCHER
1595   action( GEOMOp::OpSuppressFaces )->setEnabled( ViewOCC ); // SuppressFace
1596   action( GEOMOp::OpSuppressHoles )->setEnabled( ViewOCC ); // SuppressHole
1597   action( GEOMOp::OpCloseContour )->setEnabled( ViewOCC ); // CloseContour
1598   action( GEOMOp::OpRemoveIntWires )->setEnabled( ViewOCC ); // RemoveInternalWires
1599   action( GEOMOp::OpAddPointOnEdge )->setEnabled( ViewOCC ); // AddPointOnEdge
1600 //  action( GEOMOp::OpFreeBoundaries )->setEnabled( ViewOCC ); // Free boundaries
1601
1602   action( GEOMOp::OpGroupCreate )->setEnabled( ViewOCC ); // Create Group
1603   action( GEOMOp::OpGroupEdit )->setEnabled( ViewOCC ); // Edit Group
1604
1605   action( GEOMOp::OpMultiTransform )->setEnabled( ViewOCC ); // MENU BLOCKS - MULTI-TRANSFORMATION
1606 }
1607
1608 void GeometryGUI::windows( QMap<int, int>& mappa ) const
1609 {
1610   mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
1611   mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
1612   if ( myCreationInfoWdg )
1613     mappa.insert( myCreationInfoWdg->getWinID(), Qt::LeftDockWidgetArea );
1614 }
1615
1616 void GeometryGUI::viewManagers( QStringList& lst ) const
1617 {
1618   lst.append( OCCViewer_Viewer::Type() );
1619 }
1620
1621 void GeometryGUI::onViewManagerAdded( SUIT_ViewManager* vm )
1622 {
1623   if ( vm && vm->getType() == OCCViewer_Viewer::Type() )
1624   {
1625     qDebug( "connect" );
1626     connect( vm, SIGNAL( keyPress  ( SUIT_ViewWindow*, QKeyEvent* ) ),
1627              this, SLOT( OnKeyPress( SUIT_ViewWindow*, QKeyEvent* ) ) );
1628     connect( vm, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
1629              this, SLOT( OnMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
1630     connect( vm, SIGNAL( mouseMove ( SUIT_ViewWindow*, QMouseEvent* ) ),
1631              this, SLOT( OnMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1632     connect( vm, SIGNAL( mouseRelease ( SUIT_ViewWindow*, QMouseEvent* ) ),
1633              this, SLOT( OnMouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ) );
1634
1635     LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1636     myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1637
1638     // disable OCC selectors
1639     getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1640     QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1641     while ( itOCCSel.hasNext() )
1642       if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1643         sr->setEnabled(true);
1644   }
1645   else if ( vm->getType() == SVTK_Viewer::Type() )
1646   {
1647     LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1648     myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
1649
1650     // disable VTK selectors
1651     getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
1652     QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1653     while ( itVTKSel.hasNext() )
1654       if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1655         sr->setEnabled(true);
1656   }
1657 }
1658
1659 void GeometryGUI::onViewManagerRemoved( SUIT_ViewManager* vm )
1660 {
1661   SUIT_ViewModel* viewer = vm->getViewModel();
1662   if ( vm->getType() == OCCViewer_Viewer::Type() )
1663   {
1664     QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1665     while ( itOCCSel.hasNext() )
1666       if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1667         if ( sr->viewer() == viewer )
1668         {
1669           /*delete*/ myOCCSelectors.takeAt( myOCCSelectors.indexOf( sr ) );
1670           break;
1671         }
1672   }
1673   if ( vm->getType() == SVTK_Viewer::Type() )
1674   {
1675     QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1676     while ( itVTKSel.hasNext() )
1677       if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1678         if ( sr->viewer() == viewer )
1679         {
1680           /*delete*/ myVTKSelectors.takeAt( myVTKSelectors.indexOf( sr ) );
1681           break;
1682         }
1683   }
1684 }
1685
1686 //================================================================================
1687 /*!
1688  * \brief Slot called when selection changed. Shows creation info of a selected object 
1689  */
1690 //================================================================================
1691
1692 void GeometryGUI::updateCreationInfo()
1693 {
1694   myCreationInfoWdg->clear();
1695
1696   // Code below is commented to have myCreationInfoWdg filled as soon as it is shown again
1697   // if ( !myCreationInfoWdg->isVisible() )
1698   //   return;
1699
1700   // look for a sole selected GEOM_Object
1701   GEOM::GEOM_Object_var geomObj;
1702
1703   SALOME_ListIO selected;
1704   getApp()->selectionMgr()->selectedObjects( selected );
1705
1706   _PTR(Study) study = dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() )->studyDS();
1707   SALOME_ListIteratorOfListIO selIt( selected );
1708   for ( ; selIt.More(); selIt.Next() )
1709   {
1710     Handle(SALOME_InteractiveObject) io = selIt.Value();
1711     if ( !io->hasEntry() ) continue;
1712     _PTR(SObject) sobj = study->FindObjectID( io->getEntry() );
1713     if ( !sobj ) continue;
1714     CORBA::Object_var      obj = GeometryGUI::ClientSObjectToObject( sobj );
1715     GEOM::GEOM_Object_var gobj = GEOM::GEOM_Object::_narrow( obj );
1716     if ( !gobj->_is_nil() )
1717     {
1718       if ( !geomObj->_is_nil() )
1719         return; // several GEOM objects selected
1720       geomObj = gobj;
1721     }
1722   }
1723   if ( geomObj->_is_nil() ) return;
1724
1725   // pass creation info of geomObj to myCreationInfoWdg
1726
1727   QPixmap icon;
1728   QString operationName;
1729   myCreationInfoWdg->setOperation( icon, operationName );
1730
1731   try
1732   {
1733     OCC_CATCH_SIGNALS;
1734     GEOM::CreationInformation_var info = geomObj->GetCreationInformation();
1735     if ( &info.in() )
1736     {
1737       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1738       QString name = info->operationName.in();
1739       if ( !name.isEmpty() )
1740       {
1741         icon = resMgr->loadPixmap( "GEOM", tr( ("ICO_"+name).toLatin1().constData() ), false );
1742         operationName = tr( ("MEN_"+name).toLatin1().constData() );
1743         if ( operationName.startsWith( "MEN_" ))
1744           operationName = name; // no translation
1745         myCreationInfoWdg->setOperation( icon, operationName );
1746
1747         for ( size_t i = 0; i < info->params.length(); ++i )
1748           myCreationInfoWdg->addParam( info->params[i].name.in(),
1749                                        info->params[i].value.in() );
1750       }
1751     }
1752   }
1753   catch (...)
1754   {
1755   }
1756 }
1757
1758 QString GeometryGUI::engineIOR() const
1759 {
1760   if ( !CORBA::is_nil( GetGeomGen() ) )
1761     return QString( getApp()->orb()->object_to_string( GetGeomGen() ) );
1762   return "";
1763 }
1764
1765 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
1766 Handle(TColStd_HArray1OfByte) GeometryGUI::getTexture
1767 #else
1768 Handle(Graphic3d_HArray1OfBytes) GeometryGUI::getTexture
1769 #endif
1770       (SalomeApp_Study* theStudy, int theId, int& theWidth, int& theHeight)
1771 {
1772   theWidth = theHeight = 0;
1773
1774 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
1775   Handle(TColStd_HArray1OfByte) aTexture;
1776 #else
1777   Handle(Graphic3d_HArray1OfBytes) aTexture;
1778 #endif
1779
1780   if (theStudy) {
1781     TextureMap aTextureMap = myTextureMap[ theStudy->studyDS()->StudyId() ];
1782     aTexture = aTextureMap[ theId ];
1783     if ( aTexture.IsNull() ) {
1784       GEOM::GEOM_IInsertOperations_var aInsOp = GeometryGUI::GetGeomGen()->GetIInsertOperations( theStudy->studyDS()->StudyId() );
1785       if ( !aInsOp->_is_nil() ) {
1786         CORBA::Long aWidth, aHeight;
1787         SALOMEDS::TMPFile_var aStream = aInsOp->GetTexture( theId, aWidth, aHeight );
1788         if ( aWidth > 0 && aHeight > 0 && aStream->length() > 0 ) {
1789           theWidth  = aWidth;
1790           theHeight = aHeight;
1791
1792 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
1793           aTexture  = new TColStd_HArray1OfByte (1, aStream->length());
1794 #else
1795           aTexture  = new Graphic3d_HArray1OfBytes (1, aStream->length());
1796 #endif
1797
1798           for (int i = 0; i < aStream->length(); i++)
1799             aTexture->SetValue( i+1, (Standard_Byte)aStream[i] );
1800           aTextureMap[ theId ] = aTexture;
1801         }
1802       }
1803     }
1804   }
1805   return aTexture;
1806 }
1807
1808 LightApp_Selection* GeometryGUI::createSelection() const
1809 {
1810   return new GEOMGUI_Selection();
1811 }
1812
1813 void GeometryGUI::contextMenuPopup( const QString& client, QMenu* menu, QString& title )
1814 {
1815   SalomeApp_Module::contextMenuPopup( client, menu, title );
1816   SALOME_ListIO lst;
1817   getApp()->selectionMgr()->selectedObjects( lst );
1818
1819   //Add submenu for predefined materials
1820   bool isPredefMat = SUIT_Session::session()->resourceMgr()->booleanValue( "Geometry", "predef_materials" );
1821   if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() > 0 ) {
1822     QtxPopupMgr* mgr = popupMgr();
1823     //get parrent for submenu
1824     QAction* act = mgr->action( mgr->actionId( action(  GEOMOp::OpMaterialProperties ) ) );
1825     //Clear old  menu
1826     QMenu* oldMenu = act->menu() ;
1827     if( oldMenu ) {
1828       delete oldMenu;
1829     }
1830     if( isPredefMat ){
1831       QMenu* matMenu = new QMenu();
1832       QSignalMapper* signalMapper = new QSignalMapper( matMenu );
1833       
1834       //Get current material model for the object
1835       QVariant v;
1836       LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( getApp() );
1837       if ( anApp && anApp->activeViewManager() ) {
1838         LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( anApp->activeStudy() );
1839         if( aStudy ) {
1840           v = aStudy->getObjectProperty( anApp->activeViewManager()->getGlobalId(), lst.Last()->getEntry(), GEOM::propertyName( GEOM::Material ), QVariant() );
1841         }
1842       }
1843       QString curModel = "";
1844       if ( v.canConvert<QString>() ) curModel = v.toString();
1845       // get list of all predefined materials
1846       QStringList materials = Material_ResourceMgr::resourceMgr()->materials();
1847       bool found = false;
1848       foreach ( QString material, materials ) 
1849       {
1850         QAction* menAct = matMenu->addAction( material );
1851         connect(menAct, SIGNAL( toggled( bool ) ), signalMapper, SLOT( map() ) );
1852         signalMapper->setMapping( menAct, material );
1853         menAct->setCheckable( true );
1854         // Set checked if this material is current 
1855         Material_Model aModel;
1856         aModel.fromResources( material );
1857         if ( !found && aModel.toProperties() == curModel ) {
1858           menAct->setChecked( true );
1859           found = true;
1860         }
1861       }
1862       matMenu->insertAction( matMenu->addSeparator(), action(  GEOMOp::OpPredefMaterCustom ) );
1863       matMenu->insertSeparator( action(  GEOMOp::OpPredefMaterCustom ) );
1864       connect( signalMapper, SIGNAL( mapped( const QString & ) ),
1865                  this, SLOT( OnSetMaterial( const QString & ) ) );
1866       act->setMenu( matMenu );
1867     }
1868   }
1869   //Set name
1870   if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
1871     Handle(SALOME_InteractiveObject) io = lst.First();
1872     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
1873     _PTR(Study) study = appStudy->studyDS();
1874     _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
1875     if ( obj ) {
1876       QString aName = QString( obj->GetName().c_str() );
1877       aName.remove( QRegExp("\\s+$") );
1878       title = aName;
1879     }
1880   }
1881 }
1882
1883 void GeometryGUI::OnSetMaterial(const QString& theName)
1884 {
1885   OnGUIEvent( GEOMOp::OpPredefMaterial, QVariant( theName ) );
1886 }
1887
1888
1889 void GeometryGUI::createPreferences()
1890 {
1891   int tabId = addPreference( tr( "PREF_TAB_SETTINGS" ) );
1892
1893   int genGroup = addPreference( tr( "PREF_GROUP_GENERAL" ), tabId );
1894   setPreferenceProperty( genGroup, "columns", 2 );
1895
1896   int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), genGroup,
1897                                 LightApp_Preferences::Selector,
1898                                 "Geometry", "display_mode" );
1899
1900   addPreference( tr( "PREF_SHADING_COLOR" ), genGroup,
1901                  LightApp_Preferences::Color, "Geometry", "shading_color" );
1902
1903   addPreference( tr( "PREF_EDGES_IN_SHADING" ), genGroup,
1904                  LightApp_Preferences::Color, "Geometry", "edges_in_shading_color" );
1905
1906   addPreference( tr( "PREF_WIREFRAME_COLOR" ), genGroup,
1907                  LightApp_Preferences::Color, "Geometry", "wireframe_color" );
1908
1909   addPreference( tr( "PREF_FREE_BOUND_COLOR" ), genGroup,
1910                  LightApp_Preferences::Color, "Geometry", "free_bound_color" );
1911
1912   addPreference( tr( "PREF_LINE_COLOR"), genGroup,
1913                  LightApp_Preferences::Color, "Geometry", "line_color" );
1914
1915   addPreference( tr( "PREF_POINT_COLOR"), genGroup,
1916                  LightApp_Preferences::Color, "Geometry", "point_color" );
1917
1918   addPreference( tr( "PREF_ISOS_COLOR" ), genGroup,
1919                  LightApp_Preferences::Color, "Geometry", "isos_color" );
1920
1921   addPreference( tr( "PREF_TOPLEVEL_COLOR" ), genGroup,
1922                  LightApp_Preferences::Color, "Geometry", "toplevel_color" );
1923
1924   int top_lev_dm = addPreference( tr( "PREF_TOPLEVEL_DM" ), genGroup,
1925                       LightApp_Preferences::Selector, "Geometry", "toplevel_dm" );
1926
1927   int step = addPreference( tr( "PREF_STEP_VALUE" ), genGroup,
1928                             LightApp_Preferences::IntSpin, "Geometry", "SettingsGeomStep" );
1929
1930   int defl = addPreference( tr( "PREF_DEFLECTION" ), genGroup,
1931                             LightApp_Preferences::DblSpin, "Geometry", "deflection_coeff" );
1932
1933   addPreference( tr( "PREF_PREDEF_MATERIALS" ), genGroup,
1934                  LightApp_Preferences::Bool, "Geometry", "predef_materials" );
1935
1936   int material = addPreference( tr( "PREF_MATERIAL" ), genGroup,
1937                                 LightApp_Preferences::Selector,
1938                                 "Geometry", "material" );
1939
1940   addPreference( tr( "PREF_EDITGROUP_COLOR" ), genGroup,
1941                  LightApp_Preferences::Color, "Geometry", "editgroup_color" );
1942
1943   const int nb = 4;
1944   int wd[nb];
1945   int iter=0;
1946
1947   wd[iter++] = addPreference( tr( "PREF_EDGE_WIDTH" ), genGroup,
1948                               LightApp_Preferences::IntSpin, "Geometry", "edge_width" );
1949
1950   wd[iter++] = addPreference( tr( "PREF_ISOLINES_WIDTH" ), genGroup,
1951                               LightApp_Preferences::IntSpin, "Geometry", "isolines_width" );
1952
1953   wd[iter++] = addPreference( tr( "PREF_PREVIEW_EDGE_WIDTH" ), genGroup,
1954                                      LightApp_Preferences::IntSpin, "Geometry", "preview_edge_width" );
1955
1956   wd[iter++] = addPreference( tr( "PREF_MEASURES_LINE_WIDTH" ), genGroup,
1957                               LightApp_Preferences::IntSpin, "Geometry", "measures_line_width" );
1958
1959   for (int i = 0; i < nb; i++) {
1960     setPreferenceProperty( wd[i], "min", 1 );
1961     setPreferenceProperty( wd[i], "max", 5 );
1962   }
1963  
1964   int isoGroup = addPreference( tr( "PREF_ISOS" ), tabId );
1965   setPreferenceProperty( isoGroup, "columns", 2 );
1966   int isoU = addPreference( tr( "PREF_ISOS_U" ), isoGroup,
1967                                   LightApp_Preferences::IntSpin, "Geometry", "iso_number_u" );
1968   setPreferenceProperty( isoU, "min", 0 );
1969   setPreferenceProperty( isoU, "max", 100000 );
1970   int isoV = addPreference( tr( "PREF_ISOS_V" ), isoGroup,
1971                                  LightApp_Preferences::IntSpin, "Geometry", "iso_number_v" );
1972   setPreferenceProperty( isoV, "min", 0 );
1973   setPreferenceProperty( isoV, "max", 100000 );
1974
1975   // Quantities with individual precision settings
1976   int precGroup = addPreference( tr( "GEOM_PREF_GROUP_PRECISION" ), tabId );
1977   setPreferenceProperty( precGroup, "columns", 2 );
1978
1979   const int nbQuantities = 8;
1980   int prec[nbQuantities], ii = 0;
1981   prec[ii++] = addPreference( tr( "GEOM_PREF_length_precision" ), precGroup,
1982                               LightApp_Preferences::IntSpin, "Geometry", "length_precision" );
1983   prec[ii++] = addPreference( tr( "GEOM_PREF_angle_precision" ), precGroup,
1984                               LightApp_Preferences::IntSpin, "Geometry", "angle_precision" );
1985   prec[ii++] = addPreference( tr( "GEOM_PREF_len_tol_precision" ), precGroup,
1986                               LightApp_Preferences::IntSpin, "Geometry", "len_tol_precision" );
1987   prec[ii++] = addPreference( tr( "GEOM_PREF_ang_tol_precision" ), precGroup,
1988                               LightApp_Preferences::IntSpin, "Geometry", "ang_tol_precision" );
1989   prec[ii++] = addPreference( tr( "GEOM_PREF_weight_precision" ), precGroup,
1990                               LightApp_Preferences::IntSpin, "Geometry", "weight_precision" );
1991   prec[ii++] = addPreference( tr( "GEOM_PREF_density_precision" ), precGroup,
1992                               LightApp_Preferences::IntSpin, "Geometry", "density_precision" );
1993   prec[ii++] = addPreference( tr( "GEOM_PREF_parametric_precision" ), precGroup,
1994                               LightApp_Preferences::IntSpin, "Geometry", "parametric_precision" );
1995   prec[ii  ] = addPreference( tr( "GEOM_PREF_param_tol_precision" ), precGroup,
1996                               LightApp_Preferences::IntSpin, "Geometry", "param_tol_precision" );
1997
1998   // Set property for precision value for spinboxes
1999   for ( ii = 0; ii < nbQuantities; ii++ ){
2000     setPreferenceProperty( prec[ii], "min", -14 );
2001     setPreferenceProperty( prec[ii], "max", 14 );
2002     setPreferenceProperty( prec[ii], "precision", 2 );
2003   }
2004
2005   int VertexGroup = addPreference( tr( "PREF_GROUP_VERTEX" ), tabId );
2006   setPreferenceProperty( VertexGroup, "columns", 2 );
2007
2008   int typeOfMarker = addPreference( tr( "PREF_TYPE_OF_MARKER" ), VertexGroup,
2009                                     LightApp_Preferences::Selector, "Geometry", "type_of_marker" );
2010
2011   int markerScale = addPreference( tr( "PREF_MARKER_SCALE" ), VertexGroup,
2012                                    LightApp_Preferences::Selector, "Geometry", "marker_scale" );
2013
2014   // Set property for default display mode
2015   QStringList aModesList;
2016   aModesList.append( tr("MEN_WIREFRAME") );
2017   aModesList.append( tr("MEN_SHADING") );
2018   aModesList.append( tr("MEN_SHADING_WITH_EDGES") );
2019
2020   QList<QVariant> anIndexesList;
2021   anIndexesList.append(0);
2022   anIndexesList.append(1);
2023   anIndexesList.append(2);
2024
2025   setPreferenceProperty( dispmode, "strings", aModesList );
2026   setPreferenceProperty( dispmode, "indexes", anIndexesList );
2027
2028   // Set property for top level display mode
2029   QStringList aTopModesList;
2030   aTopModesList.append( tr("MEN_SHOW_ADD_WACTOR") );
2031   aTopModesList.append( tr("MEN_KEEP_CURRENT_DM") );
2032   aTopModesList.append( tr("MEN_WIREFRAME") );
2033   aTopModesList.append( tr("MEN_SHADING") );
2034   aTopModesList.append( tr("MEN_SHADING_WITH_EDGES") );
2035
2036   QList<QVariant> aTopIndexesList;
2037   aTopIndexesList.append(0);
2038   aTopIndexesList.append(1);
2039   aTopIndexesList.append(2);
2040   aTopIndexesList.append(3);
2041   aTopIndexesList.append(4);
2042
2043   setPreferenceProperty( top_lev_dm, "strings", aTopModesList );
2044   setPreferenceProperty( top_lev_dm, "indexes", aTopIndexesList );
2045
2046   // Set property for step value for spinboxes
2047   setPreferenceProperty( step, "min", 1 );
2048   setPreferenceProperty( step, "max", 10000 );
2049   setPreferenceProperty( step, "precision", 3 );
2050
2051   // Set property for deflection value for spinboxes
2052   setPreferenceProperty( defl, "min", GEOM::minDeflection() );
2053   setPreferenceProperty( defl, "max", 1.0 );
2054   setPreferenceProperty( defl, "step", 1.0e-04 );
2055   setPreferenceProperty( defl, "precision", 6 );
2056
2057   // Set property for default material
2058   setPreferenceProperty( material, "strings", Material_ResourceMgr::resourceMgr()->materials() );
2059   
2060   // Set property vertex marker type
2061   QList<QVariant> aMarkerTypeIndicesList;
2062   QList<QVariant> aMarkerTypeIconsList;
2063
2064   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2065   for ( int i = GEOM::MT_POINT; i < GEOM::MT_USER; i++ ) {
2066     QString icoFile = QString( "ICON_VERTEX_MARKER_%1" ).arg( i );
2067     QPixmap pixmap = resMgr->loadPixmap( "GEOM", tr( qPrintable( icoFile ) ) );
2068     aMarkerTypeIndicesList << (i-1);
2069     aMarkerTypeIconsList << pixmap;
2070   }
2071
2072   setPreferenceProperty( typeOfMarker, "indexes", aMarkerTypeIndicesList );
2073   setPreferenceProperty( typeOfMarker, "icons",   aMarkerTypeIconsList );
2074
2075   // Set property for vertex marker scale
2076   QList<QVariant> aMarkerScaleIndicesList;
2077   QStringList     aMarkerScaleValuesList;
2078
2079   for ( int iii = GEOM::MS_10; iii <= GEOM::MS_70; iii++ ) {
2080     aMarkerScaleIndicesList << iii;
2081     aMarkerScaleValuesList  << QString::number( (iii-(int)GEOM::MS_10)*0.5 + 1.0 );
2082   }
2083
2084   setPreferenceProperty( markerScale, "strings", aMarkerScaleValuesList );
2085   setPreferenceProperty( markerScale, "indexes", aMarkerScaleIndicesList );
2086
2087   int originGroup = addPreference( tr( "PREF_GROUP_ORIGIN_AND_BASE_VECTORS" ), tabId );
2088   setPreferenceProperty( originGroup, "columns", 2 );
2089
2090   int baseVectorsLength = addPreference( tr( "PREF_BASE_VECTORS_LENGTH" ), originGroup,
2091                                          LightApp_Preferences::DblSpin, "Geometry", "base_vectors_length" );
2092   setPreferenceProperty( baseVectorsLength, "min", 0.01 );
2093   setPreferenceProperty( baseVectorsLength, "max", 1000 );
2094
2095   addPreference( tr( "PREF_AUTO_CREATE" ), originGroup,
2096                  LightApp_Preferences::Bool, "Geometry", "auto_create_base_objects" );
2097
2098   int operationsGroup = addPreference( tr( "PREF_GROUP_OPERATIONS" ), tabId );
2099   setPreferenceProperty( operationsGroup, "columns", 2 );
2100
2101   addPreference( tr( "GEOM_PREVIEW" ), operationsGroup,
2102                  LightApp_Preferences::Bool, "Geometry", "geom_preview" );
2103 }
2104
2105 void GeometryGUI::preferencesChanged( const QString& section, const QString& param )
2106 {
2107   if (section == "Geometry") {
2108     SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
2109     if (param == QString("SettingsGeomStep")) {
2110       double spin_step = aResourceMgr->doubleValue(section, param, 100.);
2111       EmitSignalDefaultStepValueChanged(spin_step);
2112     }
2113     else if (param == QString("toplevel_color")) {
2114       QColor c = aResourceMgr->colorValue( "Geometry", "toplevel_color", QColor( 170, 85, 0 ) );
2115       GEOM_AISShape::setTopLevelColor(SalomeApp_Tools::color(c));
2116     }
2117     else if (param == QString("toplevel_dm")) {
2118       GEOM_AISShape::setTopLevelDisplayMode((GEOM_AISShape::TopLevelDispMode)aResourceMgr->integerValue("Geometry", "toplevel_dm", 0));
2119     }
2120   }
2121 }
2122
2123 LightApp_Displayer* GeometryGUI::displayer()
2124 {
2125   if ( !myDisplayer )
2126     myDisplayer = new GEOM_Displayer( dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) );
2127   return myDisplayer;
2128 }
2129
2130 void GeometryGUI::setLocalSelectionMode(const int mode)
2131 {
2132   myLocalSelectionMode = mode;
2133 }
2134
2135 int GeometryGUI::getLocalSelectionMode() const
2136 {
2137   return myLocalSelectionMode;
2138 }
2139
2140 const char gSeparator = '_'; // character used to separate parameter names
2141 const char gDigitsSep = ':'; // character used to separate numeric parameter values (color = r:g:b)
2142
2143 /*!
2144  * \brief Store visual parameters
2145  *
2146  * This method is called just before the study document is saved.
2147  * Store visual parameters in AttributeParameter attribute(s)
2148  */
2149 void GeometryGUI::storeVisualParameters (int savePoint)
2150 {
2151   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
2152   if ( !appStudy || !appStudy->studyDS() )
2153     return;
2154   _PTR(Study) studyDS = appStudy->studyDS();
2155
2156   // componentName is used for encoding of entries when storing them in IParameters
2157   std::string componentName = myComponentGeom->ComponentDataType();
2158   //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
2159   //if (!aSComponent) return;
2160
2161   // IParameters
2162   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
2163                                                              componentName.c_str(),
2164                                                              savePoint);
2165   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
2166
2167   QList<SUIT_ViewManager*> lst;
2168   QList<SUIT_ViewManager*>::Iterator it;
2169
2170   // main cycle to store parameters of displayed objects
2171   lst.clear();
2172   getApp()->viewManagers(lst);
2173   for (it = lst.begin(); it != lst.end(); it++) {
2174     SUIT_ViewManager* vman = *it;
2175     QString vType = vman->getType();
2176     int aMgrId = vman->getGlobalId();
2177     // saving VTK actors properties
2178     QVector<SUIT_ViewWindow*> views = vman->getViews();
2179     for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++) {
2180       const ObjMap anObjects = appStudy->getObjectMap(aMgrId);
2181       ObjMap::ConstIterator o_it = anObjects.begin();
2182       for (; o_it != anObjects.end(); o_it++) {
2183         const PropMap aProps = o_it.value();
2184
2185         //Check that object exists in the study
2186         _PTR(SObject) obj( studyDS->FindObjectID( o_it.key().toLatin1().data() ) );
2187         if ( !obj || !(aProps.count() > 0))
2188           continue;
2189         // entry is "encoded" = it does NOT contain component adress, since it is a
2190         // subject to change on next component loading
2191
2192         std::string entry = ip->encodeEntry(o_it.key().toLatin1().data(), componentName);
2193
2194         _PTR(GenericAttribute) anAttr;
2195         if (!obj->FindAttribute(anAttr, "AttributeIOR"))
2196           continue;
2197
2198         QString param, occParam = vType;
2199         occParam += GEOM::sectionSeparator();
2200         occParam += QString::number(aMgrId);
2201         occParam += GEOM::sectionSeparator();
2202
2203         if (aProps.contains(GEOM::propertyName( GEOM::Visibility ))) {
2204           param = occParam + GEOM::propertyName( GEOM::Visibility );
2205           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::Visibility )).toBool() ? "On" : "Off");
2206         }
2207
2208         if (aProps.contains(GEOM::propertyName( GEOM::DisplayMode ))) {
2209           param = occParam + GEOM::propertyName( GEOM::DisplayMode );
2210           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::DisplayMode )).toString().toStdString());
2211         }
2212
2213         if (aProps.contains(GEOM::propertyName( GEOM::Color ))) {
2214           QColor c = aProps.value(GEOM::propertyName( GEOM::Color )).value<QColor>();
2215           QStringList val;
2216           val << QString::number(c.redF());
2217           val << QString::number(c.greenF());
2218           val << QString::number(c.blueF());
2219           param = occParam + GEOM::propertyName( GEOM::Color );
2220           ip->setParameter(entry, param.toStdString(), val.join( GEOM::subSectionSeparator()).toStdString());
2221         }
2222
2223         if (vType == SVTK_Viewer::Type()) {
2224           if (aProps.contains(GEOM::propertyName( GEOM::Opacity ))) {
2225             param = occParam + GEOM::propertyName( GEOM::Opacity );
2226             ip->setParameter(entry, param.toStdString(), QString::number(1. - aProps.value(GEOM::propertyName( GEOM::Transparency )).toDouble()).toStdString());
2227           }
2228         } else if (vType == SOCC_Viewer::Type()) {
2229           if (aProps.contains(GEOM::propertyName( GEOM::Transparency ))) {
2230             param = occParam + GEOM::propertyName( GEOM::Transparency );
2231             ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::Transparency )).toString().toStdString());
2232           }
2233
2234           if (aProps.contains(GEOM::propertyName( GEOM::TopLevel ))) {
2235             param = occParam + GEOM::propertyName( GEOM::TopLevel );
2236             ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::TopLevel )).toString().toStdString());
2237           }
2238         }
2239
2240         if (aProps.contains(GEOM::propertyName( GEOM::NbIsos ))) {
2241           param = occParam + GEOM::propertyName( GEOM::NbIsos );
2242           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::NbIsos )).toString().toStdString());
2243         }
2244
2245         if (aProps.contains(GEOM::propertyName( GEOM::EdgesDirection ))) {
2246           param = occParam + GEOM::propertyName( GEOM::EdgesDirection );
2247           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::EdgesDirection )).toString().toStdString());
2248         }
2249
2250         if (aProps.contains(GEOM::propertyName( GEOM::Deflection ))) {
2251           param = occParam + GEOM::propertyName( GEOM::Deflection );
2252           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::Deflection )).toString().toStdString());
2253         }
2254
2255         //Marker type of the vertex - ONLY for the "Vertex" and "Compound of the Vertex"
2256         if (aProps.contains(GEOM::propertyName( GEOM::PointMarker ))) {
2257           param = occParam + GEOM::propertyName( GEOM::PointMarker );
2258           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::PointMarker )).toString().toStdString());
2259         }
2260
2261         if (aProps.contains(GEOM::propertyName( GEOM::Material ))) {
2262           param = occParam + GEOM::propertyName( GEOM::Material );
2263           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::Material )).toString().toStdString());
2264         }
2265
2266         if (aProps.contains(GEOM::propertyName( GEOM::LineWidth ))) {
2267              param = occParam + GEOM::propertyName( GEOM::LineWidth );
2268            ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::LineWidth )).toString().toStdString());
2269         }
2270
2271         if (aProps.contains(GEOM::propertyName( GEOM::IsosWidth ))) {
2272           param = occParam + GEOM::propertyName( GEOM::IsosWidth );
2273           ip->setParameter(entry, param.toStdString(), aProps.value(GEOM::propertyName( GEOM::IsosWidth )).toString().toStdString());
2274         }
2275       } // object iterator
2276     } // for (views)
2277   } // for (viewManagers)
2278 }
2279
2280 /*!
2281  * \brief Restore visual parameters
2282  *
2283  * This method is called after the study document is opened.
2284  * Restore visual parameters from AttributeParameter attribute(s)
2285  */
2286 void GeometryGUI::restoreVisualParameters (int savePoint)
2287 {
2288   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
2289   if (!appStudy || !appStudy->studyDS())
2290     return;
2291   _PTR(Study) studyDS = appStudy->studyDS();
2292
2293   // componentName is used for encoding of entries when storing them in IParameters
2294   std::string componentName = myComponentGeom->ComponentDataType();
2295   //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
2296   //if (!aSComponent) return;
2297
2298   // IParameters
2299   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
2300                                                              componentName.c_str(),
2301                                                              savePoint);
2302   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
2303
2304   std::vector<std::string> entries = ip->getEntries();
2305
2306   for (std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt)
2307   {
2308     // entry is a normal entry - it should be "decoded" (setting base adress of component)
2309     QString entry (ip->decodeEntry(*entIt).c_str());
2310
2311     // Check that the entry corresponds to a real object in the Study
2312     // as the object may be deleted or modified after the visual state is saved.
2313     _PTR(SObject) so = studyDS->FindObjectID(entry.toLatin1().data());
2314     if (!so) continue; //Skip the not existent entry
2315
2316     std::vector<std::string> paramNames = ip->getAllParameterNames( *entIt );
2317     std::vector<std::string> paramValues = ip->getAllParameterValues( *entIt );
2318
2319     std::vector<std::string>::iterator namesIt = paramNames.begin();
2320     std::vector<std::string>::iterator valuesIt = paramValues.begin();
2321
2322     // actors are stored in a map after displaying of them for
2323     // quicker access in the future: map < viewID to actor >
2324     NCollection_DataMap<int, GEOM_Actor*          > vtkActors;
2325     NCollection_DataMap<int, Handle(GEOM_AISShape)> occActors;
2326
2327     QString viewerTypStr;
2328     QString viewIndexStr;
2329     int viewIndex;
2330     QVector<PropMap> aListOfMap;
2331
2332     for (; namesIt != paramNames.end(); ++namesIt, ++valuesIt)
2333     {
2334       // visual parameters are stored in strings as follows: ViewerType_ViewIndex_ParamName.
2335       // '_' is used as separator and should not be used in viewer type or parameter names.
2336       QStringList lst = QString((*namesIt).c_str()).split( GEOM::sectionSeparator(), QString::SkipEmptyParts);
2337       if (lst.size() != 3)
2338         continue;
2339
2340       viewerTypStr = lst[0];
2341       viewIndexStr = lst[1];
2342       QString paramNameStr = lst[2];
2343
2344       bool ok;
2345       viewIndex = viewIndexStr.toUInt(&ok);
2346       if (!ok) // bad conversion of view index to integer
2347         continue;
2348
2349       if ((viewIndex + 1) > aListOfMap.count()) {
2350         aListOfMap.resize(viewIndex + 1);
2351       }
2352
2353       QString val((*valuesIt).c_str());
2354       if (paramNameStr == GEOM::propertyName( GEOM::Visibility )) {
2355         aListOfMap[viewIndex].insert(GEOM::propertyName( GEOM::Visibility ), val == "On");
2356       } else if (paramNameStr == GEOM::propertyName( GEOM::Opacity )) {
2357         aListOfMap[viewIndex].insert(GEOM::propertyName( GEOM::Transparency ), 1. - val.toDouble());
2358       } else if (paramNameStr == GEOM::propertyName( GEOM::Transparency )) {
2359         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::Transparency ), val.toDouble() );
2360       } else if (paramNameStr == GEOM::propertyName( GEOM::TopLevel )) {
2361         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::TopLevel ), val == "true" || val == "1");
2362       } else if (paramNameStr == GEOM::propertyName( GEOM::DisplayMode )) {
2363         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::DisplayMode ), val.toInt());
2364       } else if (paramNameStr == GEOM::propertyName( GEOM::NbIsos )) {
2365         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::NbIsos ), val);
2366       } else if (paramNameStr == GEOM::propertyName( GEOM::Color )) {
2367         QStringList rgb = val.split(GEOM::subSectionSeparator());
2368         if (rgb.count() == 3) {
2369           QColor c = QColor::fromRgbF(rgb[0].toDouble(), rgb[1].toDouble(), rgb[2].toDouble());
2370           aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::Color ), c);
2371         }
2372       } else if (paramNameStr == GEOM::propertyName( GEOM::EdgesDirection )) {
2373         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::EdgesDirection ), val == "true" || val == "1");
2374       } else if (paramNameStr == GEOM::propertyName( GEOM::Deflection )) {
2375         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::Deflection ), val.toDouble());
2376       } else if (paramNameStr == GEOM::propertyName( GEOM::PointMarker )) {
2377         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::PointMarker ), val);
2378       } else if (paramNameStr == GEOM::propertyName( GEOM::Material )) {
2379         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::Material ), val);
2380       } else if (paramNameStr == GEOM::propertyName( GEOM::LineWidth )) {
2381         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::LineWidth ), val.toInt());
2382       } else if (paramNameStr == GEOM::propertyName( GEOM::IsosWidth )) {
2383         aListOfMap[viewIndex].insert( GEOM::propertyName( GEOM::IsosWidth ), val.toInt());
2384       }
2385     } // for names/parameters iterator
2386
2387     QList<SUIT_ViewManager*> lst = getApp()->viewManagers();
2388
2389     for (int index = 0; index < aListOfMap.count(); index++) {
2390
2391       appStudy->setObjectPropMap(index, entry, aListOfMap[index]);
2392
2393       //Get Visibility property of the current PropMap
2394       if (aListOfMap[index].value(GEOM::propertyName( GEOM::Visibility )) == 1) {
2395         SUIT_ViewManager* vman = lst.at(index);
2396         SUIT_ViewModel* vmodel = vman->getViewModel();
2397         displayer()->Display(entry, true, dynamic_cast<SALOME_View*>(vmodel));
2398       }
2399     }
2400   } // for entries iterator
2401
2402   // update all VTK and OCC views
2403   QList<SUIT_ViewManager*> lst;
2404   getApp()->viewManagers(lst);
2405   for (QList<SUIT_ViewManager*>::Iterator it = lst.begin(); it != lst.end(); it++) {
2406     SUIT_ViewModel* vmodel = (*it)->getViewModel();
2407     if (!vmodel)
2408       continue;
2409     if (vmodel->getType() == SVTK_Viewer::Type()) {
2410       SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) (*it)->getActiveView();
2411       vtkView->getRenderer()->ResetCameraClippingRange();
2412       vtkView->Repaint();
2413     }
2414     else if (vmodel->getType() == SOCC_Viewer::Type()) {
2415       //SOCC_ViewWindow* occView = (SOCC_ViewWindow*) (*it)->getActiveView();
2416       SALOME_View* occVMod = dynamic_cast<SALOME_View*>(vmodel);
2417       if (occVMod)
2418         occVMod->Repaint();
2419     }
2420   }
2421 }
2422
2423 void GeometryGUI::onViewAboutToShow()
2424 {
2425   SUIT_ViewWindow* window = application()->desktop()->activeWindow();
2426   QAction* a = action( GEOMOp::OpSwitchVectors );
2427   if ( window ) {
2428     a->setEnabled(true);
2429     bool vmode = window->property("VectorsMode").toBool();
2430     a->setText ( vmode == 1 ? tr( "MEN_VECTOR_MODE_OFF" ) : tr("MEN_VECTOR_MODE_ON") );
2431   } else {
2432     a->setText ( tr("MEN_VECTOR_MODE_ON") );
2433     a->setEnabled(false);
2434   }
2435 }
2436
2437 /*!
2438   \brief Return action by id
2439   \param id identifier of the action
2440   \return action
2441 */
2442 QAction* GeometryGUI::getAction(const int id) {
2443   return action(id);
2444 }
2445
2446 /*!
2447   \brief GEOM module message handler
2448
2449   This method can be re-implemented in the subclasses.
2450   This is a GEOM module message handler.
2451
2452   \param msg the message received.
2453 */
2454 void GeometryGUI::message(const QString& msg)
2455 {
2456   // dispatch message
2457   QStringList data = msg.split("/");
2458   const int nbStrings = data.count();
2459
2460   if (nbStrings > 0) {
2461     if (data[0] == "modified") {
2462       // get mesh entry
2463       QString anIOR = nbStrings > 1 ? data[1] : QString();
2464
2465       if ( anIOR.isEmpty() ) {
2466         return;
2467       }
2468
2469       // Get the geom object.
2470       GEOM::GEOM_Object_ptr anObj = GeometryGUI::GetObjectFromIOR (anIOR);
2471
2472       // Clear the shape buffer
2473       GeometryGUI::ClearShapeBuffer (anObj);
2474     }
2475   }
2476 }
2477
2478 /*!
2479   \brief Clears the shape buffer.
2480
2481   This is a static method. It clears the shape buffer.
2482
2483   \param theObj the object
2484 */
2485 void GeometryGUI::ClearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
2486 {
2487   if ( CORBA::is_nil( theObj ) )
2488     return;
2489
2490   CORBA::String_var IOR = SalomeApp_Application::orb()->object_to_string( theObj );
2491   TCollection_AsciiString asciiIOR( (char *)IOR.in() );
2492   GEOM_Client::get_client().RemoveShapeFromBuffer( asciiIOR );
2493
2494   SALOMEDSClient_StudyManager *aManager = SalomeApp_Application::studyMgr();
2495
2496   if (!aManager)
2497     return;
2498
2499   _PTR(Study) aStudy = aManager->GetStudyByID(theObj->GetStudyID());
2500
2501   if ( !aStudy )
2502     return;
2503
2504   _PTR(SObject) aSObj ( aStudy->FindObjectIOR( std::string( IOR ) ) );
2505   if ( !aSObj )
2506     return;
2507
2508   _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
2509   for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
2510     _PTR(GenericAttribute) anAttr;
2511     if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) {
2512       _PTR(AttributeIOR) anIOR ( anAttr );
2513       TCollection_AsciiString asciiIOR( (char*)anIOR->Value().c_str() );
2514       GEOM_Client::get_client().RemoveShapeFromBuffer( asciiIOR );
2515     }
2516   }
2517 }
2518
2519 /*!
2520   \brief Returns the object from IOR.
2521
2522   This is a static method. It returns the object from its IOR.
2523
2524   \param IOR object IOR
2525   \return GEOM object.
2526 */
2527 GEOM::GEOM_Object_ptr GeometryGUI::GetObjectFromIOR( const QString& IOR )
2528 {
2529   GEOM::GEOM_Object_var geomObj;
2530   if ( !IOR.isEmpty() ) {
2531     CORBA::Object_var corbaObj = SalomeApp_Application::orb()->string_to_object
2532       ( IOR.toLatin1().constData() );
2533     if ( !CORBA::is_nil( corbaObj ) )
2534       geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
2535   }
2536   return geomObj._retn();
2537 }
2538
2539 /*!
2540   \brief Returns IOR of the object.
2541
2542   This is a static method. It returns the object's IOR.
2543
2544   \param object the GEOM object.
2545   \return object's IOR.
2546 */
2547 QString GeometryGUI::GetIORFromObject( GEOM::GEOM_Object_ptr object )
2548 {
2549   QString IOR;
2550   if ( !CORBA::is_nil( object ) ) {
2551     CORBA::String_var anIOR =
2552       SalomeApp_Application::orb()->object_to_string( object );
2553     IOR = anIOR.in();
2554   }
2555   return IOR;
2556 }
2557
2558 /*!
2559   \brief Check if this object is can't be renamed in place
2560
2561   This method can be re-implemented in the subclasses.
2562   Return true in case if object isn't reference or component (module root).
2563
2564   \param entry column id
2565   \return \c true if the item can be renamed by the user in place (e.g. in the Object browser)
2566 */
2567 bool GeometryGUI::renameAllowed( const QString& entry) const {
2568
2569   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2570   SalomeApp_Study* appStudy = app ? dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) : 0;
2571   SalomeApp_DataObject* obj = appStudy ? dynamic_cast<SalomeApp_DataObject*>(appStudy->findObjectByEntry(entry)) : 0;
2572
2573   return (app && appStudy && obj && !appStudy->isComponent(entry) && !obj->isReference());
2574 }
2575
2576 /*!
2577   Rename object by entry.
2578   \param entry entry of the object
2579   \param name new name of the object
2580   \brief Return \c true if rename operation finished successfully, \c false otherwise.
2581 */
2582 bool GeometryGUI::renameObject( const QString& entry, const QString& name)
2583 {
2584   bool result = false;
2585
2586   SalomeApp_Application* app =
2587     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication());
2588   SalomeApp_Study* appStudy = app ? dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) : 0;
2589
2590   if (!appStudy)
2591     return result;
2592
2593   _PTR(Study) aStudy = appStudy->studyDS();
2594
2595   if (!aStudy)
2596     return result;
2597
2598   bool aLocked = (_PTR(AttributeStudyProperties)(appStudy->studyDS()->GetProperties()))->IsLocked();
2599   if ( aLocked ) {
2600     SUIT_MessageBox::warning ( app->desktop(), QObject::tr("WRN_WARNING"), QObject::tr("WRN_STUDY_LOCKED") );
2601     return result;
2602   }
2603
2604   _PTR(SObject) obj ( aStudy->FindObjectID(qPrintable(entry)) );
2605   _PTR(GenericAttribute) anAttr;
2606   if ( obj ) {
2607     if ( obj->FindAttribute(anAttr, "AttributeName") ) {
2608       _PTR(AttributeName) aName (anAttr);
2609
2610       aName->SetValue( name.toLatin1().data() ); // rename the SObject
2611       GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(obj));
2612       if (!CORBA::is_nil(anObj)) {
2613         anObj->SetName( name.toLatin1().data() );  // Rename the corresponding GEOM_Object
2614       }
2615       result = true;
2616     }
2617   }
2618   return result;
2619 }
2620
2621 void GeometryGUI::updateMaterials()
2622 {
2623   LightApp_Preferences* pref = preferences();
2624   if ( pref ) {
2625     QStringList materials = Material_ResourceMgr::resourceMgr()->materials();
2626     QString currentMaterial = SUIT_Session::session()->resourceMgr()->stringValue( "Geometry", "material" );
2627     if ( !materials.contains( currentMaterial ) )
2628       // user material set as default in the preferences, might be removed
2629       SUIT_Session::session()->resourceMgr()->setValue( "Geometry", "material", QString( "Plastic" ) );
2630
2631     QtxPreferenceItem* prefItem = pref->rootItem()->findItem( tr( "PREF_MATERIAL" ), true );
2632     if ( prefItem ) {
2633       setPreferenceProperty( prefItem->id(),
2634                              "strings", materials );
2635       prefItem->retrieve();
2636     }
2637   }
2638 }
2639
2640 /*!
2641   \brief Check if the module allows "drag" operation of its objects.
2642
2643   Overloaded from LightApp_Module class.
2644   
2645   This function is a part of the general drag-n-drop mechanism.
2646   The goal of this function is to check data object passed as a parameter
2647   and decide if it can be dragged or no.
2648
2649   \param what data object being tested for drag operation
2650   \return \c true if module allows dragging of the specified object
2651   \sa isDropAccepted(), dropObjects()
2652 */
2653 bool GeometryGUI::isDraggable( const SUIT_DataObject* what ) const
2654 {
2655   // we allow dragging object under root and object from folder
2656   int aLevel = what->level();
2657   bool anObjectInFolder = false;
2658   if ( aLevel > 2 ) {
2659     const SalomeApp_DataObject* dataObj = dynamic_cast<const SalomeApp_DataObject*>( what );
2660     if ( dataObj ) {
2661       _PTR(SObject) aSO = dataObj->object();
2662       if ( aSO ) {
2663         _PTR(GenericAttribute) anAttr;
2664         _PTR(SObject) aFatherSO = aSO->GetStudy()->GetUseCaseBuilder()->GetFather( aSO );
2665         if ( aFatherSO && aFatherSO->FindAttribute(anAttr, "AttributeLocalID") ) {
2666           _PTR(AttributeLocalID) aLocalID( anAttr );
2667           anObjectInFolder = aLocalID->Value() == 999;
2668         }
2669       }
2670     }
2671   }
2672   return aLevel == 2 || anObjectInFolder;
2673 }
2674
2675 /*!
2676   \brief Check if the module allows "drop" operation on the given object.
2677
2678   Overloaded from LightApp_Module class.
2679
2680   This function is a part of the general drag-n-drop mechanism.
2681   The goal of this function is to check data object passed as a parameter
2682   and decide if it can be used as a target for the "drop" operation.
2683   The processing of the drop operation itself is done in the dropObjects() function.
2684
2685   \param where target data object
2686   \return \c true if module supports dropping on the \a where data object
2687   \sa isDraggable(), dropObjects()
2688 */
2689 bool GeometryGUI::isDropAccepted( const SUIT_DataObject* where ) const
2690 {
2691   // we allow dropping into folder and top-level GEOM object
2692   int aLevel = where->level();
2693   bool isFolder = false;
2694   if ( aLevel > 1 ) {
2695     const SalomeApp_DataObject* dataObj = dynamic_cast<const SalomeApp_DataObject*>( where );
2696     if ( dataObj ) {
2697       _PTR(SObject) aSO = dataObj->object();
2698       if ( aSO ) {
2699         _PTR(GenericAttribute) anAttr;
2700         if ( aSO->FindAttribute(anAttr, "AttributeLocalID") ) {
2701           _PTR(AttributeLocalID) aLocalID( anAttr );
2702           isFolder = aLocalID->Value() == 999;
2703         }
2704       }
2705     }
2706   }
2707   return aLevel == 1 || isFolder;
2708 }
2709
2710 /*!
2711   \brief Complete drag-n-drop operation.
2712   
2713   Overloaded from LightApp_Module class.
2714
2715   This function is a part of the general drag-n-drop mechanism.
2716   Its goal is to handle dropping of the objects being dragged according
2717   to the chosen operation (move). The dropping is performed in the
2718   context of the parent data object \a where and the \a row (position in the 
2719   children index) at which the data should be dropped. If \a row is equal to -1,
2720   this means that objects are added to the end of the children list.
2721
2722   \param what objects being dropped
2723   \param where target data object
2724   \param row child index at which the drop operation is performed
2725   \param action drag-n-drop operation (Qt::DropAction) - move
2726
2727   \sa isDraggable(), isDropAccepted()
2728 */
2729 void GeometryGUI::dropObjects( const DataObjectList& what, SUIT_DataObject* where,
2730                                const int row, Qt::DropAction action )
2731 {
2732   if (action != Qt::CopyAction && action != Qt::MoveAction)
2733     return; // unsupported action
2734
2735   // get parent object
2736   SalomeApp_DataObject* dataObj = dynamic_cast<SalomeApp_DataObject*>( where );
2737   if ( !dataObj ) return; // wrong parent
2738   _PTR(SObject) parentObj = dataObj->object();
2739
2740   // Find the current Study and StudyBuilder
2741   _PTR(Study) aStudy = parentObj->GetStudy();
2742   _PTR(UseCaseBuilder) aUseCaseBuilder = aStudy->GetUseCaseBuilder();
2743   // collect all parents of the target node
2744   QStringList parentIDs;
2745   _PTR(SObject) parent = parentObj;
2746   while( !parent->IsNull() ) {
2747     parentIDs << parent->GetID().c_str();
2748     parent = aUseCaseBuilder->GetFather(parent);
2749   }
2750
2751   // collect objects being dropped
2752   GEOM::object_list_var objects = new GEOM::object_list();
2753   objects->length( what.count() );
2754   int count = 0;
2755   for ( int i = 0; i < what.count(); i++ ) {
2756     dataObj = dynamic_cast<SalomeApp_DataObject*>( what[i] );
2757     if ( !dataObj ) continue;  // skip wrong objects
2758     _PTR(SObject) sobj = dataObj->object();
2759     // check that dropped object is not a parent of target object
2760     if ( parentIDs.contains( sobj->GetID().c_str() ) ) {
2761       return; // it's not allowed to move node into it's child 
2762     }
2763     objects[i] = _CAST(SObject, sobj)->GetSObject();
2764     count++;
2765   }
2766   objects->length( count );
2767
2768   // call engine function
2769   GetGeomGen()->Move( objects.in(),                              // what
2770                       _CAST(SObject, parentObj)->GetSObject(),   // where
2771                       row );                                     // row
2772
2773   // update Object browser
2774   getApp()->updateObjectBrowser( false );
2775 }