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