Salome HOME
Merge from BR_OPENCV
[modules/geom.git] / src / GEOMGUI / GeometryGUI.cxx
1 // Copyright (C) 2007-2011  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 #include "Python.h"
27 #include "GeometryGUI.h"
28 #include "GeometryGUI_Operations.h"
29 #include "GEOMGUI_OCCSelector.h"
30 #include "GEOMGUI_Selection.h"
31 #include "GEOM_Displayer.h"
32 #include "GEOM_AISShape.hxx"
33
34 #include "GEOM_Actor.h"
35
36 #include <SUIT_Desktop.h>
37 #include <SUIT_MessageBox.h>
38 #include <SUIT_ResourceMgr.h>
39 #include <SUIT_Session.h>
40 #include <SUIT_ViewManager.h>
41
42 #include <OCCViewer_ViewWindow.h>
43 #include <OCCViewer_ViewPort3d.h>
44 #include <OCCViewer_ViewModel.h>
45 #include <OCCViewer_ViewManager.h>
46
47 #include <SOCC_ViewModel.h>
48 #include <SOCC_ViewWindow.h>
49
50 #include <SVTK_ViewWindow.h>
51 #include <SVTK_RenderWindowInteractor.h>
52 #include <SVTK_InteractorStyle.h>
53 #include <SVTK_ViewModel.h>
54
55 #include <SalomeApp_Application.h>
56 #include <SalomeApp_DataObject.h>
57 #include <SalomeApp_Study.h>
58
59 #include <LightApp_SelectionMgr.h>
60 #include <LightApp_VTKSelector.h>
61 #include <LightApp_DataObject.h>
62 #include <LightApp_Preferences.h>
63
64 #include <SALOME_LifeCycleCORBA.hxx>
65 #include <SALOME_ListIO.hxx>
66 #include <SALOME_ListIteratorOfListIO.hxx>
67
68 #include <SALOMEDSClient_ClientFactory.hxx>
69 #include <SALOMEDSClient_IParameters.hxx>
70
71 #include <Basics_OCCTVersion.hxx>
72
73 // External includes
74 #include <QMenu>
75 #include <QTime>
76 #include <QAction>
77 #include <QFileInfo>
78 #include <QString>
79 #include <QPainter>
80
81 #include <AIS_Drawer.hxx>
82 #include <AIS_ListOfInteractive.hxx>
83 #include <AIS_ListIteratorOfListOfInteractive.hxx>
84 #include <Prs3d_Drawer.hxx>
85 #include <Prs3d_IsoAspect.hxx>
86 #include <Aspect_TypeOfMarker.hxx>
87 #include <OSD_SharedLibrary.hxx>
88 #include <NCollection_DataMap.hxx>
89
90 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
91 #include <TColStd_HArray1OfByte.hxx>
92 #else
93 #include <Graphic3d_HArray1OfBytes.hxx>
94 #endif
95
96 #include <utilities.h>
97
98 #include <vtkCamera.h>
99 #include <vtkRenderer.h>
100
101 #include <GEOM_version.h>
102
103
104 #include "GEOMImpl_Types.hxx"
105
106 extern "C" {
107   Standard_EXPORT CAM_Module* createModule() {
108     return new GeometryGUI();
109   }
110
111   Standard_EXPORT char* getModuleVersion() {
112     return (char*)GEOM_VERSION_STR;
113   }
114 }
115
116 GeometryGUI::StudyTextureMap GeometryGUI::myTextureMap;
117
118 GEOM::GEOM_Gen_var GeometryGUI::myComponentGeom = GEOM::GEOM_Gen::_nil();
119
120 GEOM::GEOM_Gen_var GeometryGUI::GetGeomGen()
121 {
122   // Bug 12290: exception in Mesh GUI on GEOMBase::GetShape() if Geometry GUI hasn't been loaded
123   if (CORBA::is_nil(myComponentGeom))
124     InitGeomGen();
125   return GeometryGUI::myComponentGeom;
126 }
127
128 bool GeometryGUI::InitGeomGen()
129 {
130   GeometryGUI aGG;
131   if( CORBA::is_nil( myComponentGeom ) ) return false;
132   return true;
133 }
134
135 //=======================================================================
136 // function : ClientSObjectToObject
137 // purpose  :
138 //=======================================================================
139 CORBA::Object_var GeometryGUI::ClientSObjectToObject (_PTR(SObject) theSObject)
140 {
141   _PTR(GenericAttribute) anAttr;
142   CORBA::Object_var anObj;
143   try {
144     std::string aValue = theSObject->GetIOR();
145     if (strcmp(aValue.c_str(), "") != 0) {
146       CORBA::ORB_ptr anORB = SalomeApp_Application::orb();
147       anObj = anORB->string_to_object(aValue.c_str());
148     }
149   } catch(...) {
150     INFOS("ClientSObjectToObject - Unknown exception was occured!!!");
151   }
152   return anObj._retn();
153 }
154
155 //=======================================================================
156 // function : ClientStudyToStudy
157 // purpose  :
158 //=======================================================================
159 SALOMEDS::Study_var GeometryGUI::ClientStudyToStudy (_PTR(Study) theStudy)
160 {
161   SALOME_NamingService *aNamingService = SalomeApp_Application::namingService();
162   CORBA::Object_var aSMObject = aNamingService->Resolve("/myStudyManager");
163   SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(aSMObject);
164   int aStudyID = theStudy->StudyId();
165   SALOMEDS::Study_var aDSStudy = aStudyManager->GetStudyByID(aStudyID);
166   return aDSStudy._retn();
167 }
168
169 void GeometryGUI::Modified( bool theIsUpdateActions )
170 {
171   if( SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() ) ) {
172     if( SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) ) {
173       appStudy->Modified();
174       if( theIsUpdateActions )
175         app->updateActions();
176     }
177   }
178 }
179
180 //=======================================================================
181 // function : GeometryGUI::GeometryGUI()
182 // purpose  : Constructor
183 //=======================================================================
184 GeometryGUI::GeometryGUI() :
185   SalomeApp_Module( "GEOM" ),
186   LightApp_Module( "GEOM" )
187 {
188   if ( CORBA::is_nil( myComponentGeom ) )
189   {
190     Engines::EngineComponent_var comp =
191       SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "GEOM" );
192     myComponentGeom = GEOM::GEOM_Gen::_narrow( comp );
193   }
194
195   myActiveDialogBox = 0;
196
197   gp_Pnt origin = gp_Pnt(0., 0., 0.);
198   gp_Dir direction = gp_Dir(0., 0., 1.);
199   myWorkingPlane = gp_Ax3(origin, direction);
200
201   myDisplayer = 0;
202   myLocalSelectionMode = GEOM_ALLOBJECTS;
203 }
204
205 //=======================================================================
206 // function : GeometryGUI::~GeometryGUI()
207 // purpose  : Destructor
208 //=======================================================================
209 GeometryGUI::~GeometryGUI()
210 {
211   while (!myOCCSelectors.isEmpty())
212     delete myOCCSelectors.takeFirst();
213
214   while (!myVTKSelectors.isEmpty())
215     delete myVTKSelectors.takeFirst();
216
217   qDeleteAll(myGUIMap);
218 }
219
220 //=======================================================================
221 // function : GeometryGUI::getLibrary()
222 // purpose  : get or load GUI library by name [ internal ]
223 //=======================================================================
224 typedef GEOMGUI* (*LibraryGUI)( GeometryGUI* );
225 GEOMGUI* GeometryGUI::getLibrary( const QString& libraryName )
226 {
227   if ( !myGUIMap.contains( libraryName ) ) {
228     // try to load library if it is not loaded yet
229 #ifndef WNT
230     QString dirs = getenv( "LD_LIBRARY_PATH" );
231     QString sep  = ":";
232 #else
233     QString dirs = getenv( "PATH" );
234     QString sep  = ";";
235 #endif
236     if ( !dirs.isEmpty() ) {
237       QStringList dirList = dirs.split(sep, QString::SkipEmptyParts ); // skip empty entries
238       QListIterator<QString> it( dirList ); it.toBack();
239       while ( it.hasPrevious() ) {
240         QFileInfo fi( Qtx::addSlash( it.previous() ) + libraryName );
241         if ( fi.exists() ) {
242           OSD_SharedLibrary aSharedLibrary( fi.fileName().toLatin1().constData() );
243           bool res = aSharedLibrary.DlOpen( OSD_RTLD_LAZY );
244           if ( !res ) {
245             MESSAGE( "Can't open library : " << aSharedLibrary.DlError() );
246             continue; // continue search further
247           }
248           OSD_Function osdF = aSharedLibrary.DlSymb( "GetLibGUI" );
249           if ( osdF != NULL ) {
250             LibraryGUI func = (GEOMGUI* (*) (GeometryGUI*))osdF;
251             GEOMGUI* libGUI = (*func)( this );
252             if ( libGUI ) {
253               myGUIMap[ libraryName ] = libGUI;
254               break; // found and loaded!
255             }
256           }
257         }
258       }
259     }
260   }
261   return myGUIMap.contains( libraryName ) ? myGUIMap[ libraryName ] : 0;
262 }
263
264 //=======================================================================
265 // function : GeometryGUI::ActiveWorkingPlane()
266 // purpose  : Activate Working Plane View
267 //=======================================================================
268 void GeometryGUI::ActiveWorkingPlane()
269 {
270   gp_Dir DZ = myWorkingPlane.Direction();
271   gp_Dir DY = myWorkingPlane.YDirection();
272
273   SUIT_ViewWindow* window = application()->desktop()->activeWindow();
274   bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
275   bool ViewVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
276
277   if( ViewOCC ) {
278     OCCViewer_ViewWindow* vw = dynamic_cast<OCCViewer_ViewWindow*>( window );
279     if ( vw ) {
280       Handle(V3d_View) view3d =  vw->getViewPort()->getView();
281
282       view3d->SetProj(DZ.X(), DZ.Y(), DZ.Z());
283       view3d->SetUp(DY.X(), DY.Y(), DY.Z());
284       vw->onViewFitAll(); 
285     }
286   }
287   else if( ViewVTK ) {
288     SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( window );
289     if ( vw ) {
290       vtkCamera* camera = vw->getRenderer()->GetActiveCamera();
291
292       camera->SetPosition(DZ.X(), DZ.Y(), DZ.Z());
293       camera->SetViewUp(DY.X(), DY.Y(), DY.Z());
294       camera->SetFocalPoint(0,0,0);
295
296       vw->onFitAll();
297     }
298   }
299 }
300
301 //=======================================================================
302 // function : GeometryGUI::SetActiveDialogBox()
303 // purpose  : Set active dialog box
304 //=======================================================================
305 void GeometryGUI::SetActiveDialogBox( QDialog* aDlg )
306 {
307   myActiveDialogBox = (QDialog*)aDlg;
308 }
309
310 //=======================================================================
311 // function : GeometryGUI::EmitSignalDeactivateDialog()
312 // purpose  : Emit a signal to deactivate the active dialog Box
313 //=======================================================================
314 void GeometryGUI::EmitSignalDeactivateDialog()
315 {
316   emit SignalDeactivateActiveDialog();
317 }
318
319 //=======================================================================
320 // function : GeometryGUI::EmitSignalCloseAllDialogs()
321 // purpose  : Emit a signal to close all non modal dialogs box
322 //=======================================================================
323 void GeometryGUI::EmitSignalCloseAllDialogs()
324 {
325   emit SignalCloseAllDialogs();
326 }
327
328 //=======================================================================
329 // function : GeometryGUI::EmitSignalDefaultStepValueChanged()
330 // purpose  : Emit a signal to inform that default real spin box step has
331 //            been changed
332 //=======================================================================
333 void GeometryGUI::EmitSignalDefaultStepValueChanged(double newVal)
334 {
335   emit SignalDefaultStepValueChanged(newVal);
336 }
337
338 //=======================================================================
339 // function : GeometryGUI::OnGUIEvent()
340 // purpose  : common slot for all menu/toolbar actions
341 //=======================================================================
342 void GeometryGUI::OnGUIEvent()
343 {
344   const QObject* obj = sender();
345   if ( !obj || !obj->inherits( "QAction" ) )
346     return;
347   int id = actionId((QAction*)obj);
348   if ( id != -1 )
349     OnGUIEvent( id );
350 }
351
352 //=======================================================================
353 // function : GeometryGUI::OnGUIEvent()
354 // purpose  : manage all events on GUI [static]
355 //=======================================================================
356 void GeometryGUI::OnGUIEvent( int id )
357 {
358   SUIT_Application* anApp = application();
359   if (!anApp) return;
360   SUIT_Desktop* desk = anApp->desktop();
361
362   // check type of the active viewframe
363   SUIT_ViewWindow* window = desk->activeWindow();
364   bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
365   bool ViewVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
366   // if current viewframe is not of OCC and not of VTK type - return immediately
367   // fix for IPAL8958 - allow some commands to execute even when NO viewer is active (rename for example)
368   QList<int> NotViewerDependentCommands;
369   NotViewerDependentCommands << GEOMOp::OpDelete
370                              << GEOMOp::OpShow
371                              << GEOMOp::OpShowOnly
372                              << GEOMOp::OpShowChildren
373                              << GEOMOp::OpHideChildren
374                              << GEOMOp::OpUnpublishObject
375                              << GEOMOp::OpPublishObject
376                              << GEOMOp::OpPointMarker;
377   if ( !ViewOCC && !ViewVTK && !NotViewerDependentCommands.contains( id ) )
378       return;
379
380   // fix for IPAL9103, point 2
381   if ( CORBA::is_nil( GetGeomGen() ) ) {
382     SUIT_MessageBox::critical( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_GET_ENGINE" ), tr( "GEOM_BUT_OK" ) );
383     return;
384   }
385
386   QString libName;
387   // find corresponding GUI library
388   switch ( id ) {
389   case GEOMOp::OpOriginAndVectors: // MENU BASIC - ORIGIN AND BASE VECTORS
390     createOriginAndBaseVectors(); // internal operation
391     return;
392   case GEOMOp::OpImport:           // MENU FILE - IMPORT
393   case GEOMOp::OpExport:           // MENU FILE - EXPORT
394   case GEOMOp::OpSelectVertex:     // POPUP MENU - SELECT ONLY - VERTEX
395   case GEOMOp::OpSelectEdge:       // POPUP MENU - SELECT ONLY - EDGE
396   case GEOMOp::OpSelectWire:       // POPUP MENU - SELECT ONLY - WIRE
397   case GEOMOp::OpSelectFace:       // POPUP MENU - SELECT ONLY - FACE
398   case GEOMOp::OpSelectShell:      // POPUP MENU - SELECT ONLY - SHELL
399   case GEOMOp::OpSelectSolid:      // POPUP MENU - SELECT ONLY - SOLID
400   case GEOMOp::OpSelectCompound:   // POPUP MENU - SELECT ONLY - COMPOUND
401   case GEOMOp::OpSelectAll:        // POPUP MENU - SELECT ONLY - SELECT ALL
402   case GEOMOp::OpDelete:           // MENU EDIT - DELETE
403   case GEOMOp::OpCheckGeom:        // MENU TOOLS - CHECK GEOMETRY
404   case GEOMOp::OpDeflection:       // POPUP MENU - DEFLECTION COEFFICIENT
405   case GEOMOp::OpColor:            // POPUP MENU - COLOR
406   case GEOMOp::OpSetTexture:       // POPUP MENU - SETTEXTURE
407   case GEOMOp::OpTransparency:     // POPUP MENU - TRANSPARENCY
408   case GEOMOp::OpIncrTransparency: // SHORTCUT   - INCREASE TRANSPARENCY
409   case GEOMOp::OpDecrTransparency: // SHORTCUT   - DECREASE TRANSPARENCY
410   case GEOMOp::OpIsos:             // POPUP MENU - ISOS
411   case GEOMOp::OpIncrNbIsos:       // SHORTCUT   - INCREASE NB ISOS
412   case GEOMOp::OpDecrNbIsos:       // SHORTCUT   - DECREASE NB ISOS
413   case GEOMOp::OpAutoColor:        // POPUP MENU - AUTO COLOR
414   case GEOMOp::OpNoAutoColor:      // POPUP MENU - DISABLE AUTO COLOR
415   case GEOMOp::OpShowChildren:     // POPUP MENU - SHOW CHILDREN
416   case GEOMOp::OpHideChildren:     // POPUP MENU - HIDE CHILDREN
417   case GEOMOp::OpUnpublishObject:  // POPUP MENU - UNPUBLISH
418   case GEOMOp::OpPublishObject:    // ROOT GEOM OBJECT - POPUP MENU - PUBLISH
419   case GEOMOp::OpPointMarker:      // POPUP MENU - POINT MARKER
420     libName = "GEOMToolsGUI";
421     break;
422   case GEOMOp::OpDisplayMode:      // MENU VIEW - WIREFRAME/SHADING
423   case GEOMOp::OpShowAll:          // MENU VIEW - SHOW ALL
424   case GEOMOp::OpShowOnly:         // MENU VIEW - DISPLAY ONLY
425   case GEOMOp::OpHideAll:          // MENU VIEW - ERASE ALL
426   case GEOMOp::OpHide:             // MENU VIEW - ERASE
427   case GEOMOp::OpShow:             // MENU VIEW - DISPLAY
428   case GEOMOp::OpSwitchVectors:    // MENU VIEW - VECTOR MODE
429   case GEOMOp::OpWireframe:        // POPUP MENU - WIREFRAME
430   case GEOMOp::OpShading:          // POPUP MENU - SHADING
431   case GEOMOp::OpTexture:          // POPUP MENU - TEXTURE
432   case GEOMOp::OpVectors:          // POPUP MENU - VECTORS
433     libName = "DisplayGUI";
434     break;
435   case GEOMOp::OpPoint:            // MENU BASIC - POINT
436   case GEOMOp::OpLine:             // MENU BASIC - LINE
437   case GEOMOp::OpCircle:           // MENU BASIC - CIRCLE
438   case GEOMOp::OpEllipse:          // MENU BASIC - ELLIPSE
439   case GEOMOp::OpArc:              // MENU BASIC - ARC
440   case GEOMOp::OpVector:           // MENU BASIC - VECTOR
441   case GEOMOp::OpPlane:            // MENU BASIC - PLANE
442   case GEOMOp::OpCurve:            // MENU BASIC - CURVE
443   case GEOMOp::OpLCS:              // MENU BASIC - LOCAL COORDINATE SYSTEM
444     libName = "BasicGUI";
445     break;
446   case GEOMOp::OpBox:              // MENU PRIMITIVE - BOX
447   case GEOMOp::OpCylinder:         // MENU PRIMITIVE - CYLINDER
448   case GEOMOp::OpSphere:           // MENU PRIMITIVE - SPHERE
449   case GEOMOp::OpTorus:            // MENU PRIMITIVE - TORUS
450   case GEOMOp::OpCone:             // MENU PRIMITIVE - CONE
451   case GEOMOp::OpRectangle:        // MENU PRIMITIVE - FACE
452   case GEOMOp::OpDisk:             // MENU PRIMITIVE - DISK
453     libName = "PrimitiveGUI";
454     break;
455   case GEOMOp::OpPrism:            // MENU GENERATION - PRISM
456   case GEOMOp::OpRevolution:       // MENU GENERATION - REVOLUTION
457   case GEOMOp::OpFilling:          // MENU GENERATION - FILLING
458   case GEOMOp::OpPipe:             // MENU GENERATION - PIPE
459     libName = "GenerationGUI";
460     break;
461   case GEOMOp::Op2dSketcher:       // MENU ENTITY - SKETCHER
462   case GEOMOp::Op3dSketcher:       // MENU ENTITY - 3D SKETCHER
463   case GEOMOp::OpExplode:          // MENU ENTITY - EXPLODE
464 #ifdef WITH_OPENCV
465   case GEOMOp::OpFeatureDetect:    // MENU ENTITY - FEATURE DETECTION
466   case GEOMOp::OpPictureImport:    // MENU ENTITY - IMPORT PICTURE IN VIEWER
467 #endif
468     libName = "EntityGUI";
469     break;
470   case GEOMOp::OpEdge:             // MENU BUILD - EDGE
471   case GEOMOp::OpWire:             // MENU BUILD - WIRE
472   case GEOMOp::OpFace:             // MENU BUILD - FACE
473   case GEOMOp::OpShell:            // MENU BUILD - SHELL
474   case GEOMOp::OpSolid:            // MENU BUILD - SOLID
475   case GEOMOp::OpCompound:         // MENU BUILD - COMPUND
476     libName = "BuildGUI";
477     break;
478   case GEOMOp::OpFuse:             // MENU BOOLEAN - FUSE
479   case GEOMOp::OpCommon:           // MENU BOOLEAN - COMMON
480   case GEOMOp::OpCut:              // MENU BOOLEAN - CUT
481   case GEOMOp::OpSection:          // MENU BOOLEAN - SECTION
482     libName = "BooleanGUI";
483     break;
484   case GEOMOp::OpTranslate:        // MENU TRANSFORMATION - TRANSLATION
485   case GEOMOp::OpRotate:           // MENU TRANSFORMATION - ROTATION
486   case GEOMOp::OpChangeLoc:        // MENU TRANSFORMATION - LOCATION
487   case GEOMOp::OpMirror:           // MENU TRANSFORMATION - MIRROR
488   case GEOMOp::OpScale:            // MENU TRANSFORMATION - SCALE
489   case GEOMOp::OpOffset:           // MENU TRANSFORMATION - OFFSET
490   case GEOMOp::OpProjection:       // MENU TRANSFORMATION - PROJECTION
491   case GEOMOp::OpMultiTranslate:   // MENU TRANSFORMATION - MULTI-TRANSLATION
492   case GEOMOp::OpMultiRotate:      // MENU TRANSFORMATION - MULTI-ROTATION
493   case GEOMOp::OpReimport:         // CONTEXT(POPUP) MENU - RELOAD_IMPORTED
494     libName = "TransformationGUI";
495     break;
496   case GEOMOp::OpPartition:        // MENU OPERATION - PARTITION
497   case GEOMOp::OpArchimede:        // MENU OPERATION - ARCHIMEDE
498   case GEOMOp::OpFillet3d:         // MENU OPERATION - FILLET
499   case GEOMOp::OpChamfer:          // MENU OPERATION - CHAMFER
500   case GEOMOp::OpClipping:         // MENU OPERATION - CLIPPING RANGE
501   case GEOMOp::OpShapesOnShape:    // MENU OPERATION - GET SHAPES ON SHAPE
502   case GEOMOp::OpFillet2d:         // MENU OPERATION - FILLET 2D
503   case GEOMOp::OpFillet1d:         // MENU OPERATION - FILLET 1D
504   case GEOMOp::OpSharedShapes:     // MENU OPERATION - GET SHARED SHAPES
505     libName = "OperationGUI";
506     break;
507   case GEOMOp::OpSewing:           // MENU REPAIR - SEWING
508   case GEOMOp::OpSuppressFaces:    // MENU REPAIR - SUPPRESS FACES
509   case GEOMOp::OpSuppressHoles:    // MENU REPAIR - SUPPRESS HOLE
510   case GEOMOp::OpShapeProcess:     // MENU REPAIR - SHAPE PROCESSING
511   case GEOMOp::OpCloseContour:     // MENU REPAIR - CLOSE CONTOUR
512   case GEOMOp::OpRemoveIntWires:   // MENU REPAIR - REMOVE INTERNAL WIRES
513   case GEOMOp::OpAddPointOnEdge:   // MENU REPAIR - ADD POINT ON EDGE
514   case GEOMOp::OpFreeBoundaries:   // MENU MEASURE - FREE BOUNDARIES
515   case GEOMOp::OpFreeFaces:        // MENU MEASURE - FREE FACES
516   case GEOMOp::OpOrientation:      // MENU REPAIR - CHANGE ORIENTATION
517   case GEOMOp::OpGlueFaces:        // MENU REPAIR - GLUE FACES
518   case GEOMOp::OpGlueEdges:        // MENU REPAIR - GLUE EDGES
519   case GEOMOp::OpLimitTolerance:   // MENU REPAIR - LIMIT TOLERANCE
520   case GEOMOp::OpRemoveExtraEdges: // MENU REPAIR - REMOVE EXTRA EDGES
521     libName = "RepairGUI";
522     break;
523   case GEOMOp::OpProperties:       // MENU MEASURE - PROPERTIES
524   case GEOMOp::OpCenterMass:       // MENU MEASURE - CDG
525   case GEOMOp::OpInertia:          // MENU MEASURE - INERTIA
526   case GEOMOp::OpNormale:          // MENU MEASURE - NORMALE
527   case GEOMOp::OpBoundingBox:      // MENU MEASURE - BOUNDING BOX
528   case GEOMOp::OpMinDistance:      // MENU MEASURE - MIN DISTANCE
529   case GEOMOp::OpAngle:            // MENU MEASURE - ANGLE
530   case GEOMOp::OpTolerance:        // MENU MEASURE - TOLERANCE
531   case GEOMOp::OpWhatIs:           // MENU MEASURE - WHATIS
532   case GEOMOp::OpCheckShape:       // MENU MEASURE - CHECK
533   case GEOMOp::OpCheckCompound:    // MENU MEASURE - CHECK COMPOUND OF BLOCKS
534   case GEOMOp::OpPointCoordinates: // MENU MEASURE - POINT COORDINATES
535     libName = "MeasureGUI";
536     break;
537   case GEOMOp::OpGroupCreate:      // MENU GROUP - CREATE
538   case GEOMOp::OpGroupCreatePopup: // POPUP MENU - CREATE GROUP
539   case GEOMOp::OpGroupEdit:        // MENU GROUP - EDIT
540     libName = "GroupGUI";
541     break;
542   case GEOMOp::OpHexaSolid:        // MENU BLOCKS - HEXAHEDRAL SOLID
543   case GEOMOp::OpMultiTransform:   // MENU BLOCKS - MULTI-TRANSFORMATION
544   case GEOMOp::OpQuadFace:         // MENU BLOCKS - QUADRANGLE FACE
545   case GEOMOp::OpPropagate:        // MENU BLOCKS - PROPAGATE
546   case GEOMOp::OpExplodeBlock:     // MENU BLOCKS - EXPLODE ON BLOCKS
547     libName = "BlocksGUI";
548     break;
549   case GEOMOp::OpAdvancedNoOp:     // NO OPERATION (advanced operations base)
550   case GEOMOp::OpPipeTShape:       // MENU NEW ENTITY - ADVANCED - PIPE TSHAPE
551 //   case GEOMOp::OpPipeTShapeGroups:     // MENU NEW ENTITY - ADVANCED - PIPE TSHAPE GROUPS
552     //@@ 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 @@//
553     libName = "AdvancedGUI";
554     break;
555   default:
556     break;
557   }
558
559   GEOMGUI* library = 0;
560   if ( !libName.isEmpty() ) {
561 #ifndef WNT
562     libName = QString( "lib" ) + libName + ".so";
563 #else
564     libName = libName + ".dll";
565 #endif
566     library = getLibrary( libName );
567   }
568
569   // call method of corresponding GUI library
570   if ( library )
571     library->OnGUIEvent( id, desk );
572   else
573     SUIT_MessageBox::critical( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_LIB_NOT_FOUND" ), tr( "GEOM_BUT_OK" ) );
574 }
575
576 //=================================================================================
577 // function : GeometryGUI::OnKeyPress()
578 // purpose  : Called when any key is pressed by user [static]
579 //=================================================================================
580 void GeometryGUI::OnKeyPress( SUIT_ViewWindow* w, QKeyEvent* e )
581 {
582   if ( !application() )
583     return;
584   foreach ( GEOMGUI* lib, myGUIMap )
585     lib->OnKeyPress( e, application()->desktop(), w );
586 }
587
588 //=================================================================================
589 // function : GeometryGUI::OnMouseMove()
590 // purpose  : Manages mouse move events [static]
591 //=================================================================================
592 void GeometryGUI::OnMouseMove( SUIT_ViewWindow* w, QMouseEvent* e )
593 {
594   if ( !application() )
595     return;
596   foreach ( GEOMGUI* lib, myGUIMap )
597     lib->OnMouseMove( e, application()->desktop(), w );
598 }
599
600 //=================================================================================
601 // function : GeometryGUI::OnMousePress()
602 // purpose  : Manage mouse press events [static]
603 //=================================================================================
604 void GeometryGUI::OnMousePress( SUIT_ViewWindow* w, QMouseEvent* e )
605 {
606   if ( !application() )
607     return;
608   foreach ( GEOMGUI* lib, myGUIMap )
609     lib->OnMousePress( e, application()->desktop(), w );
610 }
611
612 //=======================================================================
613 // function : createGeomAction
614 // purpose  :
615 //=======================================================================
616 void GeometryGUI::createGeomAction( const int id, const QString& label, const QString& icolabel,
617                                     const int accel, const bool toggle, const QString& shortcutAction )
618 {
619   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
620   QPixmap icon = icolabel.isEmpty() ? resMgr->loadPixmap( "GEOM", tr( (QString( "ICO_" )+label).toLatin1().constData() ), false )
621                                     : resMgr->loadPixmap( "GEOM", tr( icolabel.toLatin1().constData() ) );
622   createAction( id,
623                 tr( QString( "TOP_%1" ).arg( label ).toLatin1().constData() ),
624                 icon,
625                 tr( QString( "MEN_%1" ).arg( label ).toLatin1().constData() ),
626                 tr( QString( "STB_%1" ).arg( label ).toLatin1().constData() ),
627                 accel,
628                 application()->desktop(),
629                 toggle,
630                 this, SLOT( OnGUIEvent() ),
631                 shortcutAction );
632 }
633
634 //=======================================================================
635 // function : createOriginAndBaseVectors
636 // purpose  :
637 //=======================================================================
638 void GeometryGUI::createOriginAndBaseVectors()
639 {
640   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
641   if( appStudy ) {
642     _PTR(Study) studyDS = appStudy->studyDS();
643     if( studyDS && !CORBA::is_nil( GetGeomGen() ) ) {
644       GEOM::GEOM_IBasicOperations_var aBasicOperations = GetGeomGen()->GetIBasicOperations( studyDS->StudyId() );
645       if( !aBasicOperations->_is_nil() ) {
646         SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
647         double aLength = aResourceMgr->doubleValue( "Geometry", "base_vectors_length", 1.0 );
648         GEOM::GEOM_Object_var anOrigin = aBasicOperations->MakePointXYZ( 0.0, 0.0, 0.0 );
649         GEOM::GEOM_Object_var anOX = aBasicOperations->MakeVectorDXDYDZ( aLength, 0.0, 0.0 );
650         GEOM::GEOM_Object_var anOY = aBasicOperations->MakeVectorDXDYDZ( 0.0, aLength, 0.0 );
651         GEOM::GEOM_Object_var anOZ = aBasicOperations->MakeVectorDXDYDZ( 0.0, 0.0, aLength );
652
653         SALOMEDS::Study_var aDSStudy = ClientStudyToStudy( studyDS );
654         GetGeomGen()->PublishInStudy( aDSStudy, SALOMEDS::SObject::_nil(), anOrigin, "O" );
655         GetGeomGen()->PublishInStudy( aDSStudy, SALOMEDS::SObject::_nil(), anOX, "OX" );
656         GetGeomGen()->PublishInStudy( aDSStudy, SALOMEDS::SObject::_nil(), anOY, "OY" );
657         GetGeomGen()->PublishInStudy( aDSStudy, SALOMEDS::SObject::_nil(), anOZ, "OZ" );
658
659         getApp()->updateObjectBrowser( false );
660       }
661     }
662   }
663 }
664
665 //=======================================================================
666 // function : GeometryGUI::initialize()
667 // purpose  : Called when GEOM module is created
668 //=======================================================================
669 void GeometryGUI::initialize( CAM_Application* app )
670 {
671   SalomeApp_Module::initialize( app );
672
673   // ----- create actions --------------
674
675   createGeomAction( GEOMOp::OpImport,     "IMPORT", "", Qt::ControlModifier + Qt::Key_I );
676   createGeomAction( GEOMOp::OpExport,     "EXPORT", "", Qt::ControlModifier + Qt::Key_E );
677
678   createGeomAction( GEOMOp::OpDelete,     "DELETE", "", Qt::Key_Delete );
679
680   createGeomAction( GEOMOp::OpPoint,      "POINT" );
681   createGeomAction( GEOMOp::OpLine,       "LINE" );
682   createGeomAction( GEOMOp::OpCircle,     "CIRCLE" );
683   createGeomAction( GEOMOp::OpEllipse,    "ELLIPSE" );
684   createGeomAction( GEOMOp::OpArc,        "ARC" );
685   createGeomAction( GEOMOp::OpCurve,      "CURVE" );
686   createGeomAction( GEOMOp::OpVector,     "VECTOR" );
687   createGeomAction( GEOMOp::OpPlane,      "PLANE" );
688   createGeomAction( GEOMOp::OpLCS,        "LOCAL_CS" );
689   createGeomAction( GEOMOp::OpOriginAndVectors, "ORIGIN_AND_VECTORS" );
690
691   createGeomAction( GEOMOp::OpBox,        "BOX" );
692   createGeomAction( GEOMOp::OpCylinder,   "CYLINDER" );
693   createGeomAction( GEOMOp::OpSphere,     "SPHERE" );
694   createGeomAction( GEOMOp::OpTorus,      "TORUS" );
695   createGeomAction( GEOMOp::OpCone,       "CONE" );
696   createGeomAction( GEOMOp::OpRectangle,  "RECTANGLE" );
697   createGeomAction( GEOMOp::OpDisk,       "DISK" );
698
699   createGeomAction( GEOMOp::OpPrism,       "EXTRUSION" );
700   createGeomAction( GEOMOp::OpRevolution,  "REVOLUTION" );
701   createGeomAction( GEOMOp::OpFilling,     "FILLING" );
702   createGeomAction( GEOMOp::OpPipe,        "PIPE" );
703
704   createGeomAction( GEOMOp::OpGroupCreate, "GROUP_CREATE" );
705   createGeomAction( GEOMOp::OpGroupEdit,   "GROUP_EDIT" );
706
707   createGeomAction( GEOMOp::OpReimport,    "RELOAD_IMPORTED" );
708
709   createGeomAction( GEOMOp::OpQuadFace,    "Q_FACE" );
710   createGeomAction( GEOMOp::OpHexaSolid,   "HEX_SOLID" );
711
712   createGeomAction( GEOMOp::Op2dSketcher,  "SKETCH" );
713   createGeomAction( GEOMOp::Op3dSketcher,  "3DSKETCH" );
714   createGeomAction( GEOMOp::OpExplode,     "EXPLODE" );
715 #ifdef WITH_OPENCV
716   createGeomAction( GEOMOp::OpFeatureDetect,"FEATURE_DETECTION" );
717   createGeomAction( GEOMOp::OpPictureImport,"PICTURE_IMPORT" );
718 #endif
719
720   createGeomAction( GEOMOp::OpEdge,        "EDGE" );
721   createGeomAction( GEOMOp::OpWire,        "WIRE" );
722   createGeomAction( GEOMOp::OpFace,        "FACE" );
723   createGeomAction( GEOMOp::OpShell,       "SHELL" );
724   createGeomAction( GEOMOp::OpSolid,       "SOLID" );
725   createGeomAction( GEOMOp::OpCompound,    "COMPOUND" );
726
727   createGeomAction( GEOMOp::OpFuse,        "FUSE" );
728   createGeomAction( GEOMOp::OpCommon,      "COMMON" );
729   createGeomAction( GEOMOp::OpCut,         "CUT" );
730   createGeomAction( GEOMOp::OpSection,     "SECTION" );
731
732   createGeomAction( GEOMOp::OpTranslate,      "TRANSLATION" );
733   createGeomAction( GEOMOp::OpRotate,         "ROTATION" );
734   createGeomAction( GEOMOp::OpChangeLoc,      "MODIFY_LOCATION" );
735   createGeomAction( GEOMOp::OpMirror,         "MIRROR" );
736   createGeomAction( GEOMOp::OpScale,          "SCALE" );
737   createGeomAction( GEOMOp::OpOffset,         "OFFSET" );
738   createGeomAction( GEOMOp::OpProjection,     "PROJECTION" );
739   createGeomAction( GEOMOp::OpMultiTranslate, "MUL_TRANSLATION" );
740   createGeomAction( GEOMOp::OpMultiRotate,    "MUL_ROTATION" );
741
742   createGeomAction( GEOMOp::OpPartition,      "PARTITION" );
743   createGeomAction( GEOMOp::OpArchimede,      "ARCHIMEDE" );
744   createGeomAction( GEOMOp::OpFillet3d,       "FILLET" );
745   createGeomAction( GEOMOp::OpChamfer,        "CHAMFER" );
746   //createGeomAction( GEOMOp::OpClipping,        "CLIPPING" );
747   createGeomAction( GEOMOp::OpShapesOnShape,  "GET_SHAPES_ON_SHAPE" );
748   createGeomAction( GEOMOp::OpSharedShapes,   "GET_SHARED_SHAPES" );
749   createGeomAction( GEOMOp::OpFillet1d,       "FILLET_1D" );
750   createGeomAction( GEOMOp::OpFillet2d,       "FILLET_2D" );
751
752   createGeomAction( GEOMOp::OpMultiTransform, "MUL_TRANSFORM" );
753   createGeomAction( GEOMOp::OpExplodeBlock,   "EXPLODE_BLOCKS" );
754   createGeomAction( GEOMOp::OpPropagate,      "PROPAGATE" );
755
756   createGeomAction( GEOMOp::OpSewing,           "SEWING" );
757   createGeomAction( GEOMOp::OpGlueFaces,        "GLUE_FACES" );
758   createGeomAction( GEOMOp::OpGlueEdges,        "GLUE_EDGES" );
759   createGeomAction( GEOMOp::OpLimitTolerance,   "LIMIT_TOLERANCE" );
760   createGeomAction( GEOMOp::OpSuppressFaces,    "SUPPRESS_FACES" );
761   createGeomAction( GEOMOp::OpSuppressHoles,    "SUPPERSS_HOLES" );
762   createGeomAction( GEOMOp::OpShapeProcess,     "SHAPE_PROCESS" );
763   createGeomAction( GEOMOp::OpCloseContour,     "CLOSE_CONTOUR" );
764   createGeomAction( GEOMOp::OpRemoveIntWires,   "SUPPRESS_INT_WIRES" );
765   createGeomAction( GEOMOp::OpAddPointOnEdge,   "POINT_ON_EDGE" );
766   createGeomAction( GEOMOp::OpFreeBoundaries,   "CHECK_FREE_BNDS" );
767   createGeomAction( GEOMOp::OpFreeFaces,        "CHECK_FREE_FACES" );
768   createGeomAction( GEOMOp::OpOrientation,      "CHANGE_ORIENTATION" );
769   createGeomAction( GEOMOp::OpRemoveExtraEdges, "REMOVE_EXTRA_EDGES" );
770
771   createGeomAction( GEOMOp::OpPointCoordinates, "POINT_COORDS" );
772   createGeomAction( GEOMOp::OpProperties,       "BASIC_PROPS" );
773   createGeomAction( GEOMOp::OpCenterMass,       "MASS_CENTER" );
774   createGeomAction( GEOMOp::OpInertia,          "INERTIA" );
775   createGeomAction( GEOMOp::OpNormale,          "NORMALE" );
776   createGeomAction( GEOMOp::OpBoundingBox,      "BND_BOX" );
777   createGeomAction( GEOMOp::OpMinDistance,      "MIN_DIST" );
778   createGeomAction( GEOMOp::OpAngle,            "MEASURE_ANGLE" );
779
780   createGeomAction( GEOMOp::OpTolerance,        "TOLERANCE" );
781   createGeomAction( GEOMOp::OpWhatIs,           "WHAT_IS" );
782   createGeomAction( GEOMOp::OpCheckShape,       "CHECK" );
783   createGeomAction( GEOMOp::OpCheckCompound,    "CHECK_COMPOUND" );
784
785 #ifdef _DEBUG_ // PAL16821
786   createGeomAction( GEOMOp::OpCheckGeom,        "CHECK_GEOMETRY" );
787 #endif
788
789   createGeomAction( GEOMOp::OpDisplayMode,      "SHADING" );
790   createGeomAction( GEOMOp::OpShowAll,          "DISPLAY_ALL" );
791   createGeomAction( GEOMOp::OpHideAll,          "ERASE_ALL" );
792   createGeomAction( GEOMOp::OpShow,             "DISPLAY" );
793   createGeomAction( GEOMOp::OpSwitchVectors,    "VECTOR_MODE");
794   createGeomAction( GEOMOp::OpSelectVertex,     "VERTEX_SEL_ONLY" ,"", 0, true );
795   createGeomAction( GEOMOp::OpSelectEdge,       "EDGE_SEL_ONLY", "", 0, true );
796   createGeomAction( GEOMOp::OpSelectWire,       "WIRE_SEL_ONLY", "",  0, true );
797   createGeomAction( GEOMOp::OpSelectFace,       "FACE_SEL_ONLY", "", 0, true );
798   createGeomAction( GEOMOp::OpSelectShell,      "SHELL_SEL_ONLY", "",  0, true );
799   createGeomAction( GEOMOp::OpSelectSolid,      "SOLID_SEL_ONLY", "", 0, true );
800   createGeomAction( GEOMOp::OpSelectCompound,   "COMPOUND_SEL_ONLY", "",  0, true );
801   createGeomAction( GEOMOp::OpSelectAll,        "ALL_SEL_ONLY", "",  0, true );
802   createGeomAction( GEOMOp::OpShowOnly,         "DISPLAY_ONLY" );
803   createGeomAction( GEOMOp::OpHide,             "ERASE" );
804
805   createGeomAction( GEOMOp::OpWireframe,        "POP_WIREFRAME", "", 0, true );
806   createGeomAction( GEOMOp::OpShading,          "POP_SHADING", "", 0, true );
807   createGeomAction( GEOMOp::OpTexture,          "POP_TEXTURE", "", 0, true );
808   createGeomAction( GEOMOp::OpVectors,          "POP_VECTORS", "", 0, true );
809   createGeomAction( GEOMOp::OpDeflection,       "POP_DEFLECTION" );
810   createGeomAction( GEOMOp::OpColor,            "POP_COLOR" );
811   createGeomAction( GEOMOp::OpSetTexture,       "POP_SETTEXTURE" );
812   createGeomAction( GEOMOp::OpTransparency,     "POP_TRANSPARENCY" );
813   createGeomAction( GEOMOp::OpIsos,             "POP_ISOS" );
814   createGeomAction( GEOMOp::OpAutoColor,        "POP_AUTO_COLOR" );
815   createGeomAction( GEOMOp::OpNoAutoColor,      "POP_DISABLE_AUTO_COLOR" );
816   createGeomAction( GEOMOp::OpGroupCreatePopup, "POP_CREATE_GROUP" );
817   createGeomAction( GEOMOp::OpShowChildren,     "POP_SHOW_CHILDREN" );
818   createGeomAction( GEOMOp::OpHideChildren,     "POP_HIDE_CHILDREN" );
819   createGeomAction( GEOMOp::OpUnpublishObject,  "POP_UNPUBLISH_OBJ" );
820   createGeomAction( GEOMOp::OpPublishObject,    "POP_PUBLISH_OBJ" );
821   createGeomAction( GEOMOp::OpPointMarker,      "POP_POINT_MARKER" );
822
823   createGeomAction( GEOMOp::OpPipeTShape, "PIPETSHAPE" );
824
825   // Create actions for increase/decrease transparency shortcuts
826   createGeomAction( GEOMOp::OpIncrTransparency, "", "", 0, false,
827                     "Geometry:Increase transparency");
828   createGeomAction( GEOMOp::OpDecrTransparency, "", "", 0, false,
829                     "Geometry:Decrease transparency");
830
831   // Create actions for increase/decrease number of isolines
832   createGeomAction( GEOMOp::OpIncrNbIsos, "", "", 0, false,
833                     "Geometry:Increase number of isolines");
834   createGeomAction( GEOMOp::OpDecrNbIsos, "", "", 0, false,
835                     "Geometry:Decrease number of isolines");
836
837 //   createGeomAction( GEOMOp::OpPipeTShapeGroups, "PIPETSHAPEGROUPS" );
838   //@@ 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 @@//
839
840   // ---- create menus --------------------------
841
842   int fileId = createMenu( tr( "MEN_FILE" ), -1, -1 );
843   createMenu( separator(),      fileId, 10 );
844   createMenu( GEOMOp::OpImport, fileId, 10 );
845   createMenu( GEOMOp::OpExport, fileId, 10 );
846   createMenu( separator(),      fileId, -1 );
847
848   int editId = createMenu( tr( "MEN_EDIT" ), -1, -1 );
849   createMenu( GEOMOp::OpDelete, editId, -1 );
850
851   int newEntId = createMenu( tr( "MEN_NEW_ENTITY" ), -1, -1, 10 );
852
853   int basicId = createMenu( tr( "MEN_BASIC" ), newEntId, -1 );
854   createMenu( GEOMOp::OpPoint,   basicId, -1 );
855   createMenu( GEOMOp::OpLine,    basicId, -1 );
856   createMenu( GEOMOp::OpCircle,  basicId, -1 );
857   createMenu( GEOMOp::OpEllipse, basicId, -1 );
858   createMenu( GEOMOp::OpArc,     basicId, -1 );
859   createMenu( GEOMOp::OpCurve,   basicId, -1 );
860   createMenu( separator(),       basicId, -1 );
861   createMenu( GEOMOp::OpVector,  basicId, -1 );
862   createMenu( GEOMOp::OpPlane,   basicId, -1 );
863   createMenu( GEOMOp::OpLCS,     basicId, -1 );
864   createMenu( GEOMOp::OpOriginAndVectors, basicId, -1 );
865
866   int primId = createMenu( tr( "MEN_PRIMITIVES" ), newEntId, -1 );
867   createMenu( GEOMOp::OpBox,       primId, -1 );
868   createMenu( GEOMOp::OpCylinder,  primId, -1 );
869   createMenu( GEOMOp::OpSphere,    primId, -1 );
870   createMenu( GEOMOp::OpTorus,     primId, -1 );
871   createMenu( GEOMOp::OpCone,      primId, -1 );
872   createMenu( GEOMOp::OpRectangle, primId, -1 );
873   createMenu( GEOMOp::OpDisk,      primId, -1 );
874
875   int genId = createMenu( tr( "MEN_GENERATION" ), newEntId, -1 );
876   createMenu( GEOMOp::OpPrism,      genId, -1 );
877   createMenu( GEOMOp::OpRevolution, genId, -1 );
878   createMenu( GEOMOp::OpFilling,    genId, -1 );
879   createMenu( GEOMOp::OpPipe,       genId, -1 );
880
881   int advId = createMenu( tr( "MEN_ADVANCED" ), newEntId, -1 );
882   createMenu( GEOMOp::OpPipeTShape, advId, -1 );
883 //   createMenu( GEOMOp::OpPipeTShapeGroups, advId, -1 );
884   //@@ 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 @@//
885
886   createMenu( separator(), newEntId, -1 );
887
888   int groupId = createMenu( tr( "MEN_GROUP" ), newEntId, -1 );
889   createMenu( GEOMOp::OpGroupCreate, groupId, -1 );
890   createMenu( GEOMOp::OpGroupEdit,   groupId, -1 );
891
892   createMenu( separator(), newEntId, -1 );
893
894   int blocksId = createMenu( tr( "MEN_BLOCKS" ), newEntId, -1 );
895   createMenu( GEOMOp::OpQuadFace,  blocksId, -1 );
896   createMenu( GEOMOp::OpHexaSolid, blocksId, -1 );
897
898   createMenu( separator(),          newEntId, -1 );
899
900   createMenu( GEOMOp::Op2dSketcher, newEntId, -1 );
901   createMenu( GEOMOp::Op3dSketcher, newEntId, -1 );
902
903   createMenu( separator(),          newEntId, -1 );
904
905   createMenu( GEOMOp::OpExplode,    newEntId, -1 );
906
907   int buildId = createMenu( tr( "MEN_BUILD" ), newEntId, -1 );
908   createMenu( GEOMOp::OpEdge,     buildId, -1 );
909   createMenu( GEOMOp::OpWire,     buildId, -1 );
910   createMenu( GEOMOp::OpFace,     buildId, -1 );
911   createMenu( GEOMOp::OpShell,    buildId, -1 );
912   createMenu( GEOMOp::OpSolid,    buildId, -1 );
913   createMenu( GEOMOp::OpCompound, buildId, -1 );
914   
915   createMenu( separator(),          newEntId, -1 );
916   
917 #ifdef WITH_OPENCV
918   createMenu( GEOMOp::OpFeatureDetect, newEntId, -1 );
919   createMenu( GEOMOp::OpPictureImport, newEntId, -1 );
920 #endif
921
922   int operId = createMenu( tr( "MEN_OPERATIONS" ), -1, -1, 10 );
923
924   int boolId = createMenu( tr( "MEN_BOOLEAN" ), operId, -1 );
925   createMenu( GEOMOp::OpFuse,    boolId, -1 );
926   createMenu( GEOMOp::OpCommon,  boolId, -1 );
927   createMenu( GEOMOp::OpCut,     boolId, -1 );
928   createMenu( GEOMOp::OpSection, boolId, -1 );
929
930   int transId = createMenu( tr( "MEN_TRANSFORMATION" ), operId, -1 );
931   createMenu( GEOMOp::OpTranslate,      transId, -1 );
932   createMenu( GEOMOp::OpRotate,         transId, -1 );
933   createMenu( GEOMOp::OpChangeLoc,      transId, -1 );
934   createMenu( GEOMOp::OpMirror,         transId, -1 );
935   createMenu( GEOMOp::OpScale,          transId, -1 );
936   createMenu( GEOMOp::OpOffset,         transId, -1 );
937   createMenu( GEOMOp::OpProjection,     transId, -1 );
938   createMenu( separator(),              transId, -1 );
939   createMenu( GEOMOp::OpMultiTranslate, transId, -1 );
940   createMenu( GEOMOp::OpMultiRotate,    transId, -1 );
941
942   int blockId = createMenu( tr( "MEN_BLOCKS" ), operId, -1 );
943   createMenu( GEOMOp::OpMultiTransform, blockId, -1 );
944   createMenu( GEOMOp::OpExplodeBlock,   blockId, -1 );
945   createMenu( GEOMOp::OpPropagate,      blockId, -1 );
946
947   createMenu( separator(), operId, -1 );
948
949   createMenu( GEOMOp::OpPartition,     operId, -1 );
950   createMenu( GEOMOp::OpArchimede,     operId, -1 );
951   createMenu( GEOMOp::OpShapesOnShape, operId, -1 );
952   createMenu( GEOMOp::OpSharedShapes,  operId, -1 );
953
954   createMenu( separator(), operId, -1 );
955
956   createMenu( GEOMOp::OpFillet1d,      operId, -1 );
957   createMenu( GEOMOp::OpFillet2d,      operId, -1 );
958   createMenu( GEOMOp::OpFillet3d,      operId, -1 );
959   createMenu( GEOMOp::OpChamfer,       operId, -1 );
960   //createMenu( GEOMOp::OpClipping,      operId, -1 );
961
962   int repairId = createMenu( tr( "MEN_REPAIR" ), -1, -1, 10 );
963   createMenu( GEOMOp::OpShapeProcess,    repairId, -1 );
964   createMenu( GEOMOp::OpSuppressFaces,   repairId, -1 );
965   createMenu( GEOMOp::OpCloseContour,    repairId, -1 );
966   createMenu( GEOMOp::OpRemoveIntWires,  repairId, -1 );
967   createMenu( GEOMOp::OpSuppressHoles,   repairId, -1 );
968   createMenu( GEOMOp::OpSewing,          repairId, -1 );
969   createMenu( GEOMOp::OpGlueFaces,       repairId, -1 );
970   createMenu( GEOMOp::OpGlueEdges,       repairId, -1 );
971   createMenu( GEOMOp::OpLimitTolerance,  repairId, -1 );
972   createMenu( GEOMOp::OpAddPointOnEdge,  repairId, -1 );
973   //createMenu( GEOMOp::OpFreeBoundaries,  repairId, -1 );
974   //createMenu( GEOMOp::OpFreeFaces,       repairId, -1 );
975   createMenu( GEOMOp::OpOrientation,      repairId, -1 );
976   createMenu( GEOMOp::OpRemoveExtraEdges, repairId, -1 );
977
978   int measurId = createMenu( tr( "MEN_MEASURES" ), -1, -1, 10 );
979   createMenu( GEOMOp::OpPointCoordinates, measurId, -1 );
980   createMenu( GEOMOp::OpProperties,       measurId, -1 );
981   createMenu( separator(),                measurId, -1 );
982   createMenu( GEOMOp::OpCenterMass,       measurId, -1 );
983   createMenu( GEOMOp::OpInertia,          measurId, -1 );
984   createMenu( GEOMOp::OpNormale,          measurId, -1 );
985   createMenu( separator(),                measurId, -1 );
986   createMenu( GEOMOp::OpFreeBoundaries,   measurId, -1 );
987   createMenu( GEOMOp::OpFreeFaces,        measurId, -1 );
988   createMenu( separator(),                measurId, -1 );
989
990   int dimId = createMenu( tr( "MEN_DIMENSIONS" ), measurId, -1 );
991   createMenu( GEOMOp::OpBoundingBox, dimId, -1 );
992   createMenu( GEOMOp::OpMinDistance, dimId, -1 );
993   createMenu( GEOMOp::OpAngle,       dimId, -1 );
994
995   createMenu( separator(),             measurId, -1 );
996   createMenu( GEOMOp::OpTolerance,     measurId, -1 );
997   createMenu( separator(),             measurId, -1 );
998   createMenu( GEOMOp::OpWhatIs,        measurId, -1 );
999   createMenu( GEOMOp::OpCheckShape,    measurId, -1 );
1000   createMenu( GEOMOp::OpCheckCompound, measurId, -1 );
1001
1002 #ifdef _DEBUG_ // PAL16821
1003   int toolsId = createMenu( tr( "MEN_TOOLS" ), -1, -1, 50 );
1004   createMenu( separator(),         toolsId, -1 );
1005   createMenu( GEOMOp::OpCheckGeom, toolsId, -1 );
1006 #endif
1007
1008   int viewId = createMenu( tr( "MEN_VIEW" ), -1, -1 );
1009   createMenu( separator(),       viewId, -1 );
1010
1011   int dispmodeId = createMenu( tr( "MEN_DISPLAY_MODE" ), viewId, -1 );
1012   createMenu( GEOMOp::OpDisplayMode,   dispmodeId, -1 );
1013   createMenu( separator(),             dispmodeId, -1 );
1014   createMenu( GEOMOp::OpSwitchVectors, dispmodeId, -1 );
1015
1016   createMenu( separator(),       viewId, -1 );
1017   createMenu( GEOMOp::OpShowAll, viewId, -1 );
1018   createMenu( GEOMOp::OpHideAll, viewId, -1 );
1019   createMenu( separator(),       viewId, -1 );
1020   createMenu( GEOMOp::OpPublishObject, viewId, -1 );
1021   createMenu( separator(),       viewId, -1 );
1022
1023 /*
1024   PAL9111:
1025   because of these items are accessible through object browser and viewers
1026   we have removed they from main menu
1027
1028   createMenu( GEOMOp::OpShow, viewId, -1 );
1029   createMenu( GEOMOp::OpShowOnly, viewId, -1 );
1030   createMenu( GEOMOp::OpHide, viewId, -1 );
1031 */
1032
1033   // ---- create toolbars --------------------------
1034
1035   int basicTbId = createTool( tr( "TOOL_BASIC" ) );
1036   createTool( GEOMOp::OpPoint,   basicTbId );
1037   createTool( GEOMOp::OpLine,    basicTbId );
1038   createTool( GEOMOp::OpCircle,  basicTbId );
1039   createTool( GEOMOp::OpEllipse, basicTbId );
1040   createTool( GEOMOp::OpArc,     basicTbId );
1041   createTool( GEOMOp::OpCurve,   basicTbId );
1042   createTool( GEOMOp::OpVector,  basicTbId );
1043   createTool( GEOMOp::OpPlane,   basicTbId );
1044   createTool( GEOMOp::OpLCS,     basicTbId );
1045   createTool( GEOMOp::OpOriginAndVectors, basicTbId );
1046
1047   int primTbId = createTool( tr( "TOOL_PRIMITIVES" ) );
1048   createTool( GEOMOp::OpBox,       primTbId );
1049   createTool( GEOMOp::OpCylinder,  primTbId );
1050   createTool( GEOMOp::OpSphere,    primTbId );
1051   createTool( GEOMOp::OpTorus,     primTbId );
1052   createTool( GEOMOp::OpCone,      primTbId );
1053   createTool( GEOMOp::OpRectangle, primTbId );
1054   createTool( GEOMOp::OpDisk,      primTbId );
1055
1056   int boolTbId = createTool( tr( "TOOL_BOOLEAN" ) );
1057   createTool( GEOMOp::OpFuse,    boolTbId );
1058   createTool( GEOMOp::OpCommon,  boolTbId );
1059   createTool( GEOMOp::OpCut,     boolTbId );
1060   createTool( GEOMOp::OpSection, boolTbId );
1061
1062   int genTbId = createTool( tr( "TOOL_GENERATION" ) );
1063   createTool( GEOMOp::OpPrism,      genTbId );
1064   createTool( GEOMOp::OpRevolution, genTbId );
1065   createTool( GEOMOp::OpFilling,    genTbId );
1066   createTool( GEOMOp::OpPipe,       genTbId );
1067
1068   int transTbId = createTool( tr( "TOOL_TRANSFORMATION" ) );
1069   createTool( GEOMOp::OpTranslate,      transTbId );
1070   createTool( GEOMOp::OpRotate,         transTbId );
1071   createTool( GEOMOp::OpChangeLoc,      transTbId );
1072   createTool( GEOMOp::OpMirror,         transTbId );
1073   createTool( GEOMOp::OpScale,          transTbId );
1074   createTool( GEOMOp::OpOffset,         transTbId );
1075   createTool( GEOMOp::OpProjection,     transTbId );
1076   createTool( separator(),              transTbId );
1077   createTool( GEOMOp::OpMultiTranslate, transTbId );
1078   createTool( GEOMOp::OpMultiRotate,    transTbId );
1079
1080   int operTbId = createTool( tr( "TOOL_OPERATIONS" ) );
1081   createTool( GEOMOp::Op2dSketcher,      operTbId );
1082   createTool( GEOMOp::Op3dSketcher,      operTbId );
1083   createTool( separator(),               operTbId );
1084   createTool( GEOMOp::OpExplode,         operTbId );
1085   createTool( separator(),               operTbId );
1086 #ifdef WITH_OPENCV
1087   createTool( GEOMOp::OpFeatureDetect,   operTbId );
1088   createTool( GEOMOp::OpPictureImport,   operTbId );
1089   createTool( separator(),               operTbId );
1090 #endif
1091   createTool( GEOMOp::OpPartition,       operTbId );
1092   createTool( GEOMOp::OpArchimede,       operTbId );
1093   createTool( GEOMOp::OpShapesOnShape,   operTbId );
1094   createTool( GEOMOp::OpSharedShapes,    operTbId );
1095   createTool( separator(),               operTbId );
1096   createTool( GEOMOp::OpFillet1d,        operTbId );
1097   createTool( GEOMOp::OpFillet2d,        operTbId );
1098   createTool( GEOMOp::OpFillet3d,        operTbId );
1099   createTool( GEOMOp::OpChamfer,         operTbId );
1100
1101   int buildTbId = createTool( tr( "TOOL_BUILD" ) );
1102   createTool( GEOMOp::OpEdge,     buildTbId );
1103   createTool( GEOMOp::OpWire,     buildTbId );
1104   createTool( GEOMOp::OpFace,     buildTbId );
1105   createTool( GEOMOp::OpShell,    buildTbId );
1106   createTool( GEOMOp::OpSolid,    buildTbId );
1107   createTool( GEOMOp::OpCompound, buildTbId );
1108
1109   int measureTbId = createTool( tr( "TOOL_MEASURES" ) );
1110   createTool( GEOMOp::OpPointCoordinates, measureTbId );
1111   createTool( GEOMOp::OpProperties,       measureTbId );
1112   createTool( GEOMOp::OpCenterMass,       measureTbId );
1113   createTool( GEOMOp::OpInertia,          measureTbId );
1114   createTool( GEOMOp::OpNormale,          measureTbId );
1115   createTool( separator(),                measureTbId );
1116   createTool( GEOMOp::OpBoundingBox,      measureTbId );
1117   createTool( GEOMOp::OpMinDistance,      measureTbId );
1118   createTool( GEOMOp::OpAngle,            measureTbId );
1119   createTool( GEOMOp::OpTolerance  ,      measureTbId );
1120   createTool( separator(),                measureTbId );
1121   createTool( GEOMOp::OpFreeBoundaries,   measureTbId );
1122   createTool( GEOMOp::OpFreeFaces,        measureTbId );
1123   createTool( separator(),                measureTbId );
1124   createTool( GEOMOp::OpWhatIs,           measureTbId );
1125   createTool( GEOMOp::OpCheckShape,       measureTbId );
1126   createTool( GEOMOp::OpCheckCompound,    measureTbId );
1127
1128   int advancedTbId = createTool( tr( "TOOL_ADVANCED" ) );
1129   createTool( GEOMOp::OpPipeTShape, advancedTbId );
1130   //@@ 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 @@//
1131
1132   // ---- create popup menus --------------------------
1133
1134   QString clientOCCorVTK = "(client='OCCViewer' or client='VTKViewer')";
1135   QString clientOCC = "(client='OCCViewer')";
1136   QString clientOCCorVTK_AndSomeVisible = clientOCCorVTK + " and selcount>0 and isVisible";
1137   QString clientOCC_AndSomeVisible = clientOCC + " and selcount>0 and isVisible";
1138
1139   QString clientOCCorOB = "(client='ObjectBrowser' or client='OCCViewer')";
1140   QString clientOCCorVTKorOB = "(client='ObjectBrowser' or client='OCCViewer' or client='VTKViewer')";
1141   QString clientOCCorVTKorOB_AndSomeVisible = clientOCCorVTKorOB + " and selcount>0 and isVisible";
1142   QString clientOCCorOB_AndSomeVisible = clientOCCorOB + " and selcount>0 and isVisible";
1143
1144   QString autoColorPrefix =
1145     "(client='ObjectBrowser' or client='OCCViewer') and type='Shape' and selcount=1 and isOCC=true";
1146
1147   QtxPopupMgr* mgr = popupMgr();
1148
1149   mgr->insert( action(  GEOMOp::OpDelete ), -1, -1 );  // delete
1150   mgr->setRule( action( GEOMOp::OpDelete ), QString("$type in {'Shape' 'Group'} and selcount>0"), QtxPopupMgr::VisibleRule );
1151   mgr->insert( action(  GEOMOp::OpGroupCreatePopup ), -1, -1 ); // create group
1152   mgr->setRule( action( GEOMOp::OpGroupCreatePopup ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and isOCC=true"), QtxPopupMgr::VisibleRule );
1153   mgr->insert( action(  GEOMOp::OpShowChildren ), -1, -1 ); // show children
1154   mgr->setRule( action( GEOMOp::OpShowChildren ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and hasHiddenChildren=true"), QtxPopupMgr::VisibleRule );
1155
1156   mgr->insert( action(  GEOMOp::OpHideChildren ), -1, -1 ); // hide children
1157   mgr->setRule( action( GEOMOp::OpHideChildren ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and hasShownChildren=true"), QtxPopupMgr::VisibleRule );
1158   mgr->insert( action(  GEOMOp::OpGroupEdit ), -1, -1 );  // edit group
1159   mgr->setRule( action( GEOMOp::OpGroupEdit ),  QString("client='ObjectBrowser' and type='Group' and selcount=1 and isOCC=true"), QtxPopupMgr::VisibleRule );
1160   mgr->insert( separator(), -1, -1 );     // -----------
1161   dispmodeId = mgr->insert(  tr( "MEN_DISPLAY_MODE" ), -1, -1 ); // display mode menu
1162   mgr->insert( action(  GEOMOp::OpWireframe ), dispmodeId, -1 ); // wireframe
1163   mgr->setRule( action( GEOMOp::OpWireframe ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1164   mgr->setRule( action( GEOMOp::OpWireframe ), clientOCCorVTK + " and displaymode='Wireframe'", QtxPopupMgr::ToggleRule );
1165   mgr->insert( action(  GEOMOp::OpShading ), dispmodeId, -1 ); // shading
1166   mgr->setRule( action( GEOMOp::OpShading ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1167   mgr->setRule( action( GEOMOp::OpShading ), clientOCCorVTK + " and displaymode='Shading'", QtxPopupMgr::ToggleRule );
1168   mgr->insert( action(  GEOMOp::OpTexture ), dispmodeId, -1 ); // wireframe
1169   mgr->setRule( action( GEOMOp::OpTexture ), clientOCC_AndSomeVisible, QtxPopupMgr::VisibleRule );
1170   mgr->setRule( action( GEOMOp::OpTexture), clientOCC + " and displaymode='Texture'", QtxPopupMgr::ToggleRule );
1171   mgr->insert( separator(), dispmodeId, -1 );
1172   mgr->insert( action(  GEOMOp::OpVectors ), dispmodeId, -1 ); // vectors
1173   mgr->setRule( action( GEOMOp::OpVectors ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1174   mgr->setRule( action( GEOMOp::OpVectors ), clientOCCorVTK + " and isVectorsMode", QtxPopupMgr::ToggleRule );
1175   mgr->insert( separator(), -1, -1 );     // -----------
1176   mgr->insert( action(  GEOMOp::OpColor ), -1, -1 ); // color
1177   mgr->setRule( action( GEOMOp::OpColor ), clientOCCorVTKorOB_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1178   mgr->insert( action(  GEOMOp::OpTransparency ), -1, -1 ); // transparency
1179   mgr->setRule( action( GEOMOp::OpTransparency ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1180   mgr->insert( action(  GEOMOp::OpIsos ), -1, -1 ); // isos
1181   mgr->setRule( action( GEOMOp::OpIsos ), clientOCCorVTK_AndSomeVisible + " and selcount>0 and isVisible", QtxPopupMgr::VisibleRule );
1182   mgr->insert( action(  GEOMOp::OpDeflection ), -1, -1 ); // deflection
1183   mgr->setRule( action( GEOMOp::OpDeflection ), clientOCCorVTK_AndSomeVisible + " and selcount>0 and isVisible", QtxPopupMgr::VisibleRule );
1184   mgr->insert( action(  GEOMOp::OpPointMarker ), -1, -1 ); // point marker
1185   //mgr->setRule( action( GEOMOp::OpPointMarker ), QString( "selcount>0 and $typeid in {%1}" ).arg(GEOM_POINT ), QtxPopupMgr::VisibleRule );
1186   mgr->setRule( action( GEOMOp::OpPointMarker ), QString( "selcount>0 and ( $typeid in {%1} or compoundOfVertices=true ) " ).arg(GEOM::VERTEX).arg(GEOM::COMPOUND), QtxPopupMgr::VisibleRule );
1187   mgr->insert( action(  GEOMOp::OpSetTexture ), -1, -1 ); // texture
1188   mgr->setRule( action( GEOMOp::OpSetTexture ), clientOCCorOB_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1189   mgr->insert( separator(), -1, -1 );     // -----------
1190   mgr->insert( action(  GEOMOp::OpAutoColor ), -1, -1 ); // auto color
1191   mgr->setRule( action( GEOMOp::OpAutoColor ), autoColorPrefix + " and isAutoColor=false", QtxPopupMgr::VisibleRule );
1192   mgr->insert( action(  GEOMOp::OpNoAutoColor ), -1, -1 ); // disable auto color
1193   mgr->setRule( action( GEOMOp::OpNoAutoColor ), autoColorPrefix + " and isAutoColor=true", QtxPopupMgr::VisibleRule );
1194   mgr->insert( separator(), -1, -1 );     // -----------
1195
1196   QString canDisplay = "($component={'GEOM'}) and (selcount>0) and ({true} in $canBeDisplayed) ",
1197           onlyComponent = "((type='Component') and selcount=1)",
1198           rule = canDisplay + "and ((($type in {%1}) and( %2 )) or " + onlyComponent + ")",
1199           types = "'Shape' 'Group'";
1200
1201   mgr->insert( action(  GEOMOp::OpShow ), -1, -1 ); // display
1202   mgr->setRule( action( GEOMOp::OpShow ), rule.arg( types ).arg( "not isVisible" ), QtxPopupMgr::VisibleRule );
1203
1204   mgr->insert( action(  GEOMOp::OpHide ), -1, -1 ); // erase
1205   mgr->setRule( action( GEOMOp::OpHide ), rule.arg( types ).arg( "isVisible" ), QtxPopupMgr::VisibleRule );
1206
1207   mgr->insert( action(  GEOMOp::OpHideAll ), -1, -1 ); // erase All
1208   mgr->setRule( action( GEOMOp::OpHideAll ), clientOCCorVTK, QtxPopupMgr::VisibleRule );
1209
1210   QString selectOnly = "(client='OCCViewer' or client='VTKViewer') and (selcount=0)";
1211
1212   int selectonlyId = mgr->insert( tr("MEN_SELECT_ONLY"), -1, -1);                //select only menu
1213   mgr->insert( action(GEOMOp::OpSelectVertex),   selectonlyId, -1);                                  //Vertex
1214   mgr->setRule(action(GEOMOp::OpSelectVertex),   selectOnly, QtxPopupMgr::VisibleRule);
1215   mgr->setRule(action(GEOMOp::OpSelectVertex),   selectOnly + " and selectionmode='VERTEX'", QtxPopupMgr::ToggleRule);
1216   mgr->insert( action(GEOMOp::OpSelectEdge),     selectonlyId, -1);                                  //Edge
1217   mgr->setRule(action(GEOMOp::OpSelectEdge),     selectOnly, QtxPopupMgr::VisibleRule);
1218   mgr->setRule(action(GEOMOp::OpSelectEdge),     selectOnly + " and selectionmode='EDGE'", QtxPopupMgr::ToggleRule);
1219   mgr->insert( action(GEOMOp::OpSelectWire),     selectonlyId, -1);                                  //Wire
1220   mgr->setRule(action(GEOMOp::OpSelectWire),     selectOnly, QtxPopupMgr::VisibleRule);
1221   mgr->setRule(action(GEOMOp::OpSelectWire),     selectOnly + " and selectionmode='WIRE'", QtxPopupMgr::ToggleRule);
1222   mgr->insert( action(GEOMOp::OpSelectFace),     selectonlyId, -1);                                  //Face
1223   mgr->setRule(action(GEOMOp::OpSelectFace),     selectOnly, QtxPopupMgr::VisibleRule);
1224   mgr->setRule(action(GEOMOp::OpSelectFace),     selectOnly + " and selectionmode='FACE'", QtxPopupMgr::ToggleRule);
1225   mgr->insert( action(GEOMOp::OpSelectShell),    selectonlyId, -1);                                  //Shell
1226   mgr->setRule(action(GEOMOp::OpSelectShell),    selectOnly, QtxPopupMgr::VisibleRule);
1227   mgr->setRule(action(GEOMOp::OpSelectShell),    selectOnly + " and selectionmode='SHELL'", QtxPopupMgr::ToggleRule);
1228   mgr->insert( action(GEOMOp::OpSelectSolid),    selectonlyId, -1);                                  //Solid
1229   mgr->setRule(action(GEOMOp::OpSelectSolid),    selectOnly, QtxPopupMgr::VisibleRule);
1230   mgr->setRule(action(GEOMOp::OpSelectSolid),    selectOnly + " and selectionmode='SOLID'", QtxPopupMgr::ToggleRule);
1231   mgr->insert( action(GEOMOp::OpSelectCompound), selectonlyId, -1);                                  //Compound
1232   mgr->setRule(action(GEOMOp::OpSelectCompound), selectOnly, QtxPopupMgr::VisibleRule);
1233   mgr->setRule(action(GEOMOp::OpSelectCompound), selectOnly + " and selectionmode='COMPOUND'", QtxPopupMgr::ToggleRule);
1234   mgr->insert( separator(), selectonlyId, -1);
1235   mgr->insert( action(GEOMOp::OpSelectAll),      selectonlyId, -1);                                  //Clear selection filter
1236   mgr->setRule(action(GEOMOp::OpSelectAll),      selectOnly, QtxPopupMgr::VisibleRule);
1237   mgr->setRule(action(GEOMOp::OpSelectAll),      selectOnly + " and selectionmode='ALL'", QtxPopupMgr::ToggleRule);
1238   mgr->insert( action(GEOMOp::OpShowOnly ), -1, -1 ); // display only
1239   mgr->setRule(action(GEOMOp::OpShowOnly ), rule.arg( types ).arg( "true" ), QtxPopupMgr::VisibleRule );
1240   mgr->insert( separator(), -1, -1 );
1241
1242   mgr->insert( separator(), -1, -1 );     // -----------
1243   mgr->insert( action(  GEOMOp::OpUnpublishObject ), -1, -1 ); // Unpublish object
1244   mgr->setRule( action( GEOMOp::OpUnpublishObject ), QString("client='ObjectBrowser' and $type in {'Shape' 'Group'} and selcount>0"), QtxPopupMgr::VisibleRule );
1245
1246
1247   mgr->insert( action(  GEOMOp::OpPublishObject ), -1, -1 ); // Publish object
1248   mgr->setRule( action( GEOMOp::OpPublishObject ), QString("client='ObjectBrowser' and isComponent=true"), QtxPopupMgr::VisibleRule );
1249
1250   mgr->insert( action(  GEOMOp::OpReimport ), -1, -1 );  // delete
1251   mgr->setRule( action( GEOMOp::OpReimport ), QString("$imported in {'true'} and selcount>0"), QtxPopupMgr::VisibleRule );
1252
1253   mgr->hide( mgr->actionId( action( myEraseAll ) ) );
1254 }
1255
1256 //=======================================================================
1257 // function : GeometryGUI::activateModule()
1258 // purpose  : Called when GEOM module is activated
1259 //=======================================================================
1260 bool GeometryGUI::activateModule( SUIT_Study* study )
1261 {
1262   if ( CORBA::is_nil( myComponentGeom ) )
1263     return false;
1264
1265   bool res = SalomeApp_Module::activateModule( study );
1266
1267   if ( !res )
1268     return false;
1269   setMenuShown( true );
1270   setToolShown( true );
1271
1272   // import Python module that manages GEOM plugins (need to be here because SalomePyQt API uses active module)
1273   PyGILState_STATE gstate = PyGILState_Ensure();
1274   PyObject* pluginsmanager=PyImport_ImportModuleNoBlock((char*)"salome_pluginsmanager");
1275   if(pluginsmanager==NULL)
1276     PyErr_Print();
1277   else
1278     {
1279       PyObject* result=PyObject_CallMethod( pluginsmanager, (char*)"initialize", (char*)"isss",1,"geom",tr("MEN_NEW_ENTITY").toStdString().c_str(),tr("GEOM_PLUGINS_OTHER").toStdString().c_str());
1280       if(result==NULL)
1281         PyErr_Print();
1282       Py_XDECREF(result);
1283     }
1284   PyGILState_Release(gstate);
1285   // end of GEOM plugins loading
1286
1287   connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1288           this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1289
1290   // Reset actions accelerator keys
1291   action(GEOMOp::OpImport)->setEnabled( true ); // Import: CTRL + Key_I
1292   action(GEOMOp::OpExport)->setEnabled( true ); // Export: CTRL + Key_E
1293   action(GEOMOp::OpDelete)->setEnabled( true ); // Delete: Key_Delete
1294
1295   GUIMap::Iterator it;
1296   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1297     it.value()->activate( application()->desktop() );
1298
1299   LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1300
1301   SUIT_ViewManager* vm;
1302   ViewManagerList OCCViewManagers, VTKViewManagers;
1303
1304   application()->viewManagers( OCCViewer_Viewer::Type(), OCCViewManagers );
1305   QListIterator<SUIT_ViewManager*> itOCC( OCCViewManagers );
1306   while ( itOCC.hasNext() && (vm = itOCC.next()) )
1307     myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1308
1309   application()->viewManagers( SVTK_Viewer::Type(), VTKViewManagers );
1310   QListIterator<SUIT_ViewManager*> itVTK( VTKViewManagers );
1311   while ( itVTK.hasNext() && (vm = itVTK.next()) )
1312     myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
1313
1314   //NPAL 19674
1315   SALOME_ListIO selected;
1316   sm->selectedObjects( selected );
1317   sm->clearSelected();
1318
1319   // disable OCC selectors
1320   getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1321   QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1322   while ( itOCCSel.hasNext() )
1323     if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1324       sr->setEnabled(true);
1325
1326   // disable VTK selectors
1327   getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
1328   QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1329   while ( itVTKSel.hasNext() )
1330     if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1331       sr->setEnabled(true);
1332
1333   sm->setSelectedObjects( selected, true );   //NPAL 19674
1334
1335   QMenu* viewMenu = menuMgr()->findMenu( STD_Application::MenuViewId );
1336   if ( viewMenu )
1337     connect( viewMenu, SIGNAL( aboutToShow() ), this, SLOT( onViewAboutToShow() ) );
1338
1339   // 0020836 (Basic vectors and origin)
1340   SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
1341   if( aResourceMgr->booleanValue( "Geometry", "auto_create_base_objects", false ) ) {
1342     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
1343     if( appStudy ) {
1344       _PTR(Study) studyDS = appStudy->studyDS();
1345       if( studyDS ) {
1346         _PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
1347         if( !aSComponent ) // create objects automatically only if there is no GEOM component
1348           createOriginAndBaseVectors();
1349       }
1350     }
1351   }
1352
1353   return true;
1354 }
1355
1356
1357 //=======================================================================
1358 // function : GeometryGUI::deactivateModule()
1359 // purpose  : Called when GEOM module is deactivated
1360 //=======================================================================
1361 bool GeometryGUI::deactivateModule( SUIT_Study* study )
1362 {
1363   QMenu* viewMenu = menuMgr()->findMenu( STD_Application::MenuViewId );
1364   if ( viewMenu )
1365     disconnect( viewMenu, SIGNAL( aboutToShow() ), this, SLOT( onViewAboutToShow() ) );
1366
1367   setMenuShown( false );
1368   setToolShown( false );
1369
1370   disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1371              this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1372
1373   EmitSignalCloseAllDialogs();
1374
1375   GUIMap::Iterator it;
1376   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1377     it.value()->deactivate();
1378
1379   // Unset actions accelerator keys
1380   action(GEOMOp::OpImport)->setEnabled( false ); // Import: CTRL + Key_I
1381   action(GEOMOp::OpExport)->setEnabled( false ); // Export: CTRL + Key_E
1382   action(GEOMOp::OpDelete)->setEnabled( false ); // Delete: Key_Delete
1383
1384   qDeleteAll(myOCCSelectors);
1385   myOCCSelectors.clear();
1386   getApp()->selectionMgr()->setEnabled( true, OCCViewer_Viewer::Type() );
1387
1388   qDeleteAll(myVTKSelectors);
1389   myVTKSelectors.clear();
1390   getApp()->selectionMgr()->setEnabled( true, SVTK_Viewer::Type() );
1391
1392   return SalomeApp_Module::deactivateModule( study );
1393 }
1394
1395 //=======================================================================
1396 // function : onWindowActivated()
1397 // purpose  : update menu items' status - disable non-OCC-viewer-compatible actions
1398 //=======================================================================
1399 void GeometryGUI::onWindowActivated( SUIT_ViewWindow* win )
1400 {
1401   if ( !win )
1402     return;
1403
1404   const bool ViewOCC = ( win->getViewManager()->getType() == OCCViewer_Viewer::Type() );
1405   //const bool ViewVTK = ( win->getViewManager()->getType() == SVTK_Viewer::Type() );
1406
1407   // disable non-OCC viewframe menu commands
1408 //  action( GEOMOp::Op2dSketcher )->setEnabled( ViewOCC ); // SKETCHER
1409   action( GEOMOp::OpSuppressFaces )->setEnabled( ViewOCC ); // SuppressFace
1410   action( GEOMOp::OpSuppressHoles )->setEnabled( ViewOCC ); // SuppressHole
1411   action( GEOMOp::OpCloseContour )->setEnabled( ViewOCC ); // CloseContour
1412   action( GEOMOp::OpRemoveIntWires )->setEnabled( ViewOCC ); // RemoveInternalWires
1413   action( GEOMOp::OpAddPointOnEdge )->setEnabled( ViewOCC ); // AddPointOnEdge
1414 //  action( GEOMOp::OpFreeBoundaries )->setEnabled( ViewOCC ); // Free boundaries
1415
1416   action( GEOMOp::OpGroupCreate )->setEnabled( ViewOCC ); // Create Group
1417   action( GEOMOp::OpGroupEdit )->setEnabled( ViewOCC ); // Edit Group
1418
1419   action( GEOMOp::OpMultiTransform )->setEnabled( ViewOCC ); // MENU BLOCKS - MULTI-TRANSFORMATION
1420 }
1421
1422 void GeometryGUI::windows( QMap<int, int>& mappa ) const
1423 {
1424   mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
1425   mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
1426 }
1427
1428 void GeometryGUI::viewManagers( QStringList& lst ) const
1429 {
1430   lst.append( OCCViewer_Viewer::Type() );
1431 }
1432
1433 void GeometryGUI::onViewManagerAdded( SUIT_ViewManager* vm )
1434 {
1435   if ( vm && vm->getType() == OCCViewer_Viewer::Type() )
1436   {
1437     qDebug( "connect" );
1438     connect( vm, SIGNAL( keyPress  ( SUIT_ViewWindow*, QKeyEvent* ) ),
1439              this, SLOT( OnKeyPress( SUIT_ViewWindow*, QKeyEvent* ) ) );
1440     connect( vm, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
1441              this, SLOT( OnMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
1442     connect( vm, SIGNAL( mouseMove ( SUIT_ViewWindow*, QMouseEvent* ) ),
1443              this, SLOT( OnMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1444
1445     LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1446     myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1447
1448     // disable OCC selectors
1449     getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1450     QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1451     while ( itOCCSel.hasNext() )
1452       if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1453         sr->setEnabled(true);
1454   }
1455   else if ( vm->getType() == SVTK_Viewer::Type() )
1456   {
1457     LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1458     myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
1459
1460     // disable VTK selectors
1461     getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
1462     QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1463     while ( itVTKSel.hasNext() )
1464       if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1465         sr->setEnabled(true);
1466   }
1467 }
1468
1469 void GeometryGUI::onViewManagerRemoved( SUIT_ViewManager* vm )
1470 {
1471   SUIT_ViewModel* viewer = vm->getViewModel();
1472   if ( vm->getType() == OCCViewer_Viewer::Type() )
1473   {
1474     QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1475     while ( itOCCSel.hasNext() )
1476       if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1477         if ( sr->viewer() == viewer )
1478         {
1479           delete myOCCSelectors.takeAt( myOCCSelectors.indexOf( sr ) );
1480           break;
1481         }
1482   }
1483   if ( vm->getType() == SVTK_Viewer::Type() )
1484   {
1485     QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1486     while ( itVTKSel.hasNext() )
1487       if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1488         if ( sr->viewer() == viewer )
1489         {
1490           delete myVTKSelectors.takeAt( myVTKSelectors.indexOf( sr ) );
1491           break;
1492         }
1493   }
1494 }
1495
1496 QString GeometryGUI::engineIOR() const
1497 {
1498   if ( !CORBA::is_nil( GetGeomGen() ) )
1499     return QString( getApp()->orb()->object_to_string( GetGeomGen() ) );
1500   return "";
1501 }
1502
1503 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
1504 Handle(TColStd_HArray1OfByte) GeometryGUI::getTexture
1505 #else
1506 Handle(Graphic3d_HArray1OfBytes) GeometryGUI::getTexture
1507 #endif
1508       (SalomeApp_Study* theStudy, int theId, int& theWidth, int& theHeight)
1509 {
1510   theWidth = theHeight = 0;
1511
1512 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
1513   Handle(TColStd_HArray1OfByte) aTexture;
1514 #else
1515   Handle(Graphic3d_HArray1OfBytes) aTexture;
1516 #endif
1517
1518   if (theStudy) {
1519     TextureMap aTextureMap = myTextureMap[ theStudy->studyDS()->StudyId() ];
1520     aTexture = aTextureMap[ theId ];
1521     if ( aTexture.IsNull() ) {
1522       GEOM::GEOM_IInsertOperations_var aInsOp = GeometryGUI::GetGeomGen()->GetIInsertOperations( theStudy->studyDS()->StudyId() );
1523       if ( !aInsOp->_is_nil() ) {
1524         CORBA::Long aWidth, aHeight;
1525         SALOMEDS::TMPFile_var aStream = aInsOp->GetTexture( theId, aWidth, aHeight );
1526         if ( aWidth > 0 && aHeight > 0 && aStream->length() > 0 ) {
1527           theWidth  = aWidth;
1528           theHeight = aHeight;
1529
1530 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
1531           aTexture  = new TColStd_HArray1OfByte (1, aStream->length());
1532 #else
1533           aTexture  = new Graphic3d_HArray1OfBytes (1, aStream->length());
1534 #endif
1535
1536           for (int i = 0; i < aStream->length(); i++)
1537             aTexture->SetValue( i+1, (Standard_Byte)aStream[i] );
1538           aTextureMap[ theId ] = aTexture;
1539         }
1540       }
1541     }
1542   }
1543   return aTexture;
1544 }
1545
1546 LightApp_Selection* GeometryGUI::createSelection() const
1547 {
1548   return new GEOMGUI_Selection();
1549 }
1550
1551 void GeometryGUI::contextMenuPopup( const QString& client, QMenu* menu, QString& title )
1552 {
1553   SalomeApp_Module::contextMenuPopup( client, menu, title );
1554
1555   /*
1556   SALOME_ListIO lst;
1557   getApp()->selectionMgr()->selectedObjects(lst);
1558   if (lst.Extent() < 1)
1559     return;
1560
1561   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
1562   _PTR(Study) study = appStudy->studyDS();
1563
1564   bool isImported = true;
1565   SALOME_ListIteratorOfListIO anIt (lst);
1566   for (; anIt.More() && isImported; anIt.Next()) {
1567     Handle(SALOME_InteractiveObject) io = anIt.Value();
1568     _PTR(SObject) aSObj = study->FindObjectID(io->getEntry());
1569     if (aSObj) {
1570       if (lst.Extent() == 1) {
1571         // Set context menu title
1572         if (client == "OCCViewer" || client == "VTKViewer")
1573           title = QString(aSObj->GetName().c_str());
1574       }
1575
1576       CORBA::Object_var anObj = GeometryGUI::ClientSObjectToObject(aSObj);
1577       GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(anObj);
1578       if (CORBA::is_nil(aGeomObj) || aGeomObj->GetType() != GEOM_IMPORT)
1579         isImported = false;
1580     } else {
1581       isImported = false;
1582     }
1583   }
1584
1585   if (isImported) {
1586     menu->addAction(action(GEOMOp::OpReimport)); // Reload imported shape
1587   }
1588   */
1589 }
1590
1591 void GeometryGUI::createPreferences()
1592 {
1593   int tabId = addPreference( tr( "PREF_TAB_SETTINGS" ) );
1594
1595   int genGroup = addPreference( tr( "PREF_GROUP_GENERAL" ), tabId );
1596   setPreferenceProperty( genGroup, "columns", 2 );
1597
1598   int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), genGroup,
1599                                 LightApp_Preferences::Selector,
1600                                 "Geometry", "display_mode" );
1601
1602   addPreference( tr( "PREF_SHADING_COLOR" ), genGroup,
1603                  LightApp_Preferences::Color, "Geometry", "shading_color" );
1604
1605   addPreference( tr( "PREF_WIREFRAME_COLOR" ), genGroup,
1606                  LightApp_Preferences::Color, "Geometry", "wireframe_color" );
1607
1608   addPreference( tr( "PREF_FREE_BOUND_COLOR" ), genGroup,
1609                  LightApp_Preferences::Color, "Geometry", "free_bound_color" );
1610
1611   addPreference( tr( "PREF_LINE_COLOR"), genGroup,
1612                  LightApp_Preferences::Color, "Geometry", "line_color" );
1613
1614   addPreference( tr( "PREF_POINT_COLOR"), genGroup,
1615                  LightApp_Preferences::Color, "Geometry", "point_color" );
1616
1617   addPreference( tr( "PREF_ISOS_COLOR" ), genGroup,
1618                  LightApp_Preferences::Color, "Geometry", "isos_color" );
1619
1620   int step = addPreference( tr( "PREF_STEP_VALUE" ), genGroup,
1621                             LightApp_Preferences::IntSpin, "Geometry", "SettingsGeomStep" );
1622
1623   int defl = addPreference( tr( "PREF_DEFLECTION" ), genGroup,
1624                             LightApp_Preferences::DblSpin, "Geometry", "deflection_coeff" );
1625
1626   // Quantities with individual precision settings
1627   int precGroup = addPreference( tr( "GEOM_PREF_GROUP_PRECISION" ), tabId );
1628   setPreferenceProperty( precGroup, "columns", 2 );
1629
1630   const int nbQuantities = 8;
1631   int prec[nbQuantities], ii = 0;
1632   prec[ii++] = addPreference( tr( "GEOM_PREF_length_precision" ), precGroup,
1633                               LightApp_Preferences::IntSpin, "Geometry", "length_precision" );
1634   prec[ii++] = addPreference( tr( "GEOM_PREF_angle_precision" ), precGroup,
1635                               LightApp_Preferences::IntSpin, "Geometry", "angle_precision" );
1636   prec[ii++] = addPreference( tr( "GEOM_PREF_len_tol_precision" ), precGroup,
1637                               LightApp_Preferences::IntSpin, "Geometry", "len_tol_precision" );
1638   prec[ii++] = addPreference( tr( "GEOM_PREF_ang_tol_precision" ), precGroup,
1639                               LightApp_Preferences::IntSpin, "Geometry", "ang_tol_precision" );
1640   prec[ii++] = addPreference( tr( "GEOM_PREF_weight_precision" ), precGroup,
1641                               LightApp_Preferences::IntSpin, "Geometry", "weight_precision" );
1642   prec[ii++] = addPreference( tr( "GEOM_PREF_density_precision" ), precGroup,
1643                               LightApp_Preferences::IntSpin, "Geometry", "density_precision" );
1644   prec[ii++] = addPreference( tr( "GEOM_PREF_parametric_precision" ), precGroup,
1645                               LightApp_Preferences::IntSpin, "Geometry", "parametric_precision" );
1646   prec[ii  ] = addPreference( tr( "GEOM_PREF_param_tol_precision" ), precGroup,
1647                               LightApp_Preferences::IntSpin, "Geometry", "param_tol_precision" );
1648
1649   // Set property for precision value for spinboxes
1650   for ( ii = 0; ii < nbQuantities; ii++ ){
1651     setPreferenceProperty( prec[ii], "min", -14 );
1652     setPreferenceProperty( prec[ii], "max", 14 );
1653     setPreferenceProperty( prec[ii], "precision", 2 );
1654   }
1655
1656   int VertexGroup = addPreference( tr( "PREF_GROUP_VERTEX" ), tabId );
1657   setPreferenceProperty( VertexGroup, "columns", 2 );
1658
1659   int typeOfMarker = addPreference( tr( "PREF_TYPE_OF_MARKER" ), VertexGroup,
1660                                     LightApp_Preferences::Selector, "Geometry", "type_of_marker" );
1661
1662   int markerScale = addPreference( tr( "PREF_MARKER_SCALE" ), VertexGroup,
1663                                    LightApp_Preferences::Selector, "Geometry", "marker_scale" );
1664
1665   // Set property for default display mode
1666   QStringList aModesList;
1667   aModesList.append( tr("MEN_WIREFRAME") );
1668   aModesList.append( tr("MEN_SHADING") );
1669
1670   QList<QVariant> anIndexesList;
1671   anIndexesList.append(0);
1672   anIndexesList.append(1);
1673
1674   setPreferenceProperty( dispmode, "strings", aModesList );
1675   setPreferenceProperty( dispmode, "indexes", anIndexesList );
1676
1677   // Set property for step value for spinboxes
1678   setPreferenceProperty( step, "min", 1 );
1679   setPreferenceProperty( step, "max", 10000 );
1680   setPreferenceProperty( step, "precision", 3 );
1681
1682   // Set property for deflection value for spinboxes
1683   setPreferenceProperty( defl, "min", DEFLECTION_MIN );
1684   setPreferenceProperty( defl, "max", 1.0 );
1685   setPreferenceProperty( defl, "step", 1.0e-04 );
1686   setPreferenceProperty( defl, "precision", 6 );
1687
1688   // Set property vertex marker type
1689   QList<QVariant> aMarkerTypeIndicesList;
1690   QList<QVariant> aMarkerTypeIconsList;
1691
1692   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1693   for ( int i = GEOM::MT_POINT; i < GEOM::MT_USER; i++ ) {
1694     QString icoFile = QString( "ICON_VERTEX_MARKER_%1" ).arg( i );
1695     QPixmap pixmap = resMgr->loadPixmap( "GEOM", tr( qPrintable( icoFile ) ) );
1696     aMarkerTypeIndicesList << (i-1);
1697     aMarkerTypeIconsList << pixmap;
1698   }
1699
1700   setPreferenceProperty( typeOfMarker, "indexes", aMarkerTypeIndicesList );
1701   setPreferenceProperty( typeOfMarker, "icons",   aMarkerTypeIconsList );
1702
1703   // Set property for vertex marker scale
1704   QList<QVariant> aMarkerScaleIndicesList;
1705   QStringList     aMarkerScaleValuesList;
1706
1707   for ( int iii = GEOM::MS_10; iii <= GEOM::MS_70; iii++ ) {
1708     aMarkerScaleIndicesList << iii;
1709     aMarkerScaleValuesList  << QString::number( (iii-(int)GEOM::MS_10)*0.5 + 1.0 );
1710   }
1711
1712   setPreferenceProperty( markerScale, "strings", aMarkerScaleValuesList );
1713   setPreferenceProperty( markerScale, "indexes", aMarkerScaleIndicesList );
1714
1715   int originGroup = addPreference( tr( "PREF_GROUP_ORIGIN_AND_BASE_VECTORS" ), tabId );
1716   setPreferenceProperty( originGroup, "columns", 2 );
1717
1718   int baseVectorsLength = addPreference( tr( "PREF_BASE_VECTORS_LENGTH" ), originGroup,
1719                                          LightApp_Preferences::DblSpin, "Geometry", "base_vectors_length" );
1720   setPreferenceProperty( baseVectorsLength, "min", 0.01 );
1721   setPreferenceProperty( baseVectorsLength, "max", 1000 );
1722
1723   addPreference( tr( "PREF_AUTO_CREATE" ), originGroup,
1724                  LightApp_Preferences::Bool, "Geometry", "auto_create_base_objects" );
1725
1726
1727   int operationsGroup = addPreference( tr( "PREF_GROUP_OPERATIONS" ), tabId );
1728   setPreferenceProperty( operationsGroup, "columns", 2 );
1729
1730   addPreference( tr( "GEOM_PREVIEW" ), operationsGroup,
1731                  LightApp_Preferences::Bool, "Geometry", "geom_preview" );
1732 }
1733
1734 void GeometryGUI::preferencesChanged( const QString& section, const QString& param )
1735 {
1736   if (section == "Geometry") {
1737     SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
1738     if (param == QString("SettingsGeomStep")) {
1739       double spin_step = aResourceMgr->doubleValue(section, param, 100.);
1740       EmitSignalDefaultStepValueChanged(spin_step);
1741     }
1742   }
1743 }
1744
1745 LightApp_Displayer* GeometryGUI::displayer()
1746 {
1747   if( !myDisplayer )
1748     myDisplayer = new GEOM_Displayer( dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) );
1749   return myDisplayer;
1750 }
1751
1752 void GeometryGUI::setLocalSelectionMode(const int mode)
1753 {
1754   myLocalSelectionMode = mode;
1755 }
1756 int GeometryGUI::getLocalSelectionMode() const
1757 {
1758   return myLocalSelectionMode;
1759 }
1760
1761 const char gSeparator = '_'; // character used to separate parameter names
1762 const char gDigitsSep = ':'; // character used to separate numeric parameter values (color = r:g:b)
1763
1764 /*!
1765  * \brief Store visual parameters
1766  *
1767  * This method is called just before the study document is saved.
1768  * Store visual parameters in AttributeParameter attribue(s)
1769  */
1770 void GeometryGUI::storeVisualParameters (int savePoint)
1771 {
1772   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
1773   if ( !appStudy || !appStudy->studyDS() )
1774     return;
1775   _PTR(Study) studyDS = appStudy->studyDS();
1776
1777   // componentName is used for encoding of entries when storing them in IParameters
1778   std::string componentName = myComponentGeom->ComponentDataType();
1779   //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
1780   //if (!aSComponent) return;
1781
1782   // IParameters
1783   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
1784                                                              componentName.c_str(),
1785                                                              savePoint);
1786   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
1787
1788   QList<SUIT_ViewManager*> lst;
1789   QList<SUIT_ViewManager*>::Iterator it;
1790
1791   // main cycle to store parameters of displayed objects
1792   lst.clear();
1793   getApp()->viewManagers(lst);
1794   for (it = lst.begin(); it != lst.end(); it++) {
1795     SUIT_ViewManager* vman = *it;
1796     QString vType = vman->getType();
1797     int aMgrId = vman->getGlobalId();
1798     // saving VTK actors properties
1799     QVector<SUIT_ViewWindow*> views = vman->getViews();
1800     for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++) {
1801       const ObjMap anObjects = appStudy->getObjectMap(aMgrId);
1802       ObjMap::ConstIterator o_it = anObjects.begin();
1803       for (; o_it != anObjects.end(); o_it++) {
1804         const PropMap aProps = o_it.value();
1805
1806         //Check that object exists in the study
1807         _PTR(SObject) obj( studyDS->FindObjectID( o_it.key().toLatin1().data() ) );
1808         if ( !obj || !(aProps.count() > 0))
1809           continue;
1810         // entry is "encoded" = it does NOT contain component adress, since it is a
1811         // subject to change on next component loading
1812
1813         std::string entry = ip->encodeEntry(o_it.key().toLatin1().data(), componentName);
1814
1815         _PTR(GenericAttribute) anAttr;
1816         if( !obj->FindAttribute(anAttr, "AttributeIOR"))
1817           continue;
1818
1819         std::string param,occParam = vType.toLatin1().data();
1820         occParam += NAME_SEPARATOR;
1821         occParam += QString::number(aMgrId).toLatin1().data();
1822         occParam += NAME_SEPARATOR;
1823
1824         if(aProps.contains(VISIBILITY_PROP)) {
1825           param = occParam + VISIBILITY_PROP;
1826           ip->setParameter(entry, param, aProps.value(VISIBILITY_PROP).toInt() == 1 ? "On" : "Off");
1827         }
1828
1829         if(aProps.contains(DISPLAY_MODE_PROP)) {
1830           param = occParam + DISPLAY_MODE_PROP;
1831           ip->setParameter(entry, param, QString::number(aProps.value(DISPLAY_MODE_PROP).toInt()).toLatin1().data());
1832         }
1833
1834         if(aProps.contains(COLOR_PROP)) {
1835           QColor c = aProps.value(COLOR_PROP).value<QColor>();
1836           QString colorStr = QString::number(c.red()/255.);
1837           colorStr += DIGIT_SEPARATOR; colorStr += QString::number(c.green()/255.);
1838           colorStr += DIGIT_SEPARATOR; colorStr += QString::number(c.blue()/255.);
1839           param = occParam + COLOR_PROP;
1840           ip->setParameter(entry, param, colorStr.toLatin1().data());
1841         }
1842
1843         if(vType == SVTK_Viewer::Type()) {
1844           if(aProps.contains(OPACITY_PROP)) {
1845             param = occParam + OPACITY_PROP;
1846             ip->setParameter(entry, param, QString::number(1. - aProps.value(TRANSPARENCY_PROP).toDouble()).toLatin1().data());
1847           }
1848         } else if (vType == SOCC_Viewer::Type()) {
1849           if(aProps.contains(TRANSPARENCY_PROP)) {
1850             param = occParam + TRANSPARENCY_PROP;
1851             ip->setParameter(entry, param, QString::number(aProps.value(TRANSPARENCY_PROP).toDouble()).toLatin1().data());
1852           }
1853         }
1854
1855         if(aProps.contains(ISOS_PROP)) {
1856           param = occParam + ISOS_PROP;
1857           ip->setParameter(entry, param, aProps.value(ISOS_PROP).toString().toLatin1().data());
1858         }
1859
1860         if(aProps.contains(VECTOR_MODE_PROP)) {
1861           param = occParam + VECTOR_MODE_PROP;
1862           ip->setParameter(entry, param, QString::number(aProps.value(VECTOR_MODE_PROP).toInt()).toLatin1().data());
1863         }
1864
1865         if(aProps.contains(DEFLECTION_COEFF_PROP)) {
1866           param = occParam + DEFLECTION_COEFF_PROP;
1867           ip->setParameter(entry, param, QString::number(aProps.value(DEFLECTION_COEFF_PROP).toDouble()).toLatin1().data());
1868         }
1869
1870         //Marker type of the vertex - ONLY for the "Vertex" and "Compound of the Vertex"
1871         if(aProps.contains(MARKER_TYPE_PROP)) {
1872           param = occParam + MARKER_TYPE_PROP;
1873           ip->setParameter(entry, param, aProps.value(MARKER_TYPE_PROP).toString().toLatin1().data());
1874         }
1875       } // object iterator
1876     } // for (views)
1877   } // for (viewManagers)
1878 }
1879
1880 /*!
1881  * \brief Restore visual parameters
1882  *
1883  * This method is called after the study document is opened.
1884  * Restore visual parameters from AttributeParameter attribue(s)
1885  */
1886 void GeometryGUI::restoreVisualParameters (int savePoint)
1887 {
1888   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
1889   if (!appStudy || !appStudy->studyDS())
1890     return;
1891   _PTR(Study) studyDS = appStudy->studyDS();
1892
1893   // componentName is used for encoding of entries when storing them in IParameters
1894   std::string componentName = myComponentGeom->ComponentDataType();
1895   //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
1896   //if (!aSComponent) return;
1897
1898   // IParameters
1899   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
1900                                                              componentName.c_str(),
1901                                                              savePoint);
1902   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
1903
1904   std::vector<std::string> entries = ip->getEntries();
1905
1906   for (std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt)
1907   {
1908     // entry is a normal entry - it should be "decoded" (setting base adress of component)
1909     QString entry (ip->decodeEntry(*entIt).c_str());
1910
1911     // Check that the entry corresponds to a real object in the Study
1912     // as the object may be deleted or modified after the visual state is saved.
1913     _PTR(SObject) so = studyDS->FindObjectID(entry.toLatin1().data());
1914     if (!so) continue; //Skip the not existent entry
1915
1916     std::vector<std::string> paramNames = ip->getAllParameterNames( *entIt );
1917     std::vector<std::string> paramValues = ip->getAllParameterValues( *entIt );
1918
1919     std::vector<std::string>::iterator namesIt = paramNames.begin();
1920     std::vector<std::string>::iterator valuesIt = paramValues.begin();
1921
1922     // actors are stored in a map after displaying of them for
1923     // quicker access in the future: map < viewID to actor >
1924     NCollection_DataMap<int, GEOM_Actor*          > vtkActors;
1925     NCollection_DataMap<int, Handle(GEOM_AISShape)> occActors;
1926
1927     QString viewerTypStr;
1928     QString viewIndexStr;
1929     int viewIndex;
1930     QVector<PropMap> aListOfMap;
1931
1932     for (; namesIt != paramNames.end(); ++namesIt, ++valuesIt)
1933     {
1934       // visual parameters are stored in strings as follows: ViewerType_ViewIndex_ParamName.
1935       // '_' is used as separator and should not be used in viewer type or parameter names.
1936       QStringList lst = QString((*namesIt).c_str()).split(NAME_SEPARATOR, QString::SkipEmptyParts);
1937       if (lst.size() != 3)
1938         continue;
1939
1940       viewerTypStr = lst[0];
1941       viewIndexStr = lst[1];
1942       QString paramNameStr = lst[2];
1943
1944       bool ok;
1945       viewIndex = viewIndexStr.toUInt(&ok);
1946       if (!ok) // bad conversion of view index to integer
1947         continue;
1948
1949       if((viewIndex + 1) > aListOfMap.count()) {
1950         aListOfMap.resize(viewIndex + 1);
1951       }
1952
1953       QString val((*valuesIt).c_str());
1954       if(paramNameStr == VISIBILITY_PROP){
1955         aListOfMap[viewIndex].insert(VISIBILITY_PROP, val == "On" ? 1 : 0);
1956
1957       } else if(paramNameStr == OPACITY_PROP) {
1958         aListOfMap[viewIndex].insert(TRANSPARENCY_PROP, 1. - val.toDouble());
1959
1960       }        else if(paramNameStr == TRANSPARENCY_PROP) {
1961         aListOfMap[viewIndex].insert(TRANSPARENCY_PROP, val.toDouble());
1962
1963       } else if(paramNameStr == DISPLAY_MODE_PROP) {
1964         aListOfMap[viewIndex].insert( DISPLAY_MODE_PROP, val.toInt());
1965
1966       } else if(paramNameStr == ISOS_PROP) {
1967         aListOfMap[viewIndex].insert( ISOS_PROP, val);
1968
1969       } else if(paramNameStr == COLOR_PROP) {
1970         QStringList rgb = val.split(DIGIT_SEPARATOR);
1971         if(rgb.count() == 3) {
1972           QColor c(int(rgb[0].toDouble()*255), int(rgb[1].toDouble()*255), int(rgb[2].toDouble()*255));
1973           aListOfMap[viewIndex].insert( COLOR_PROP, c);
1974         }
1975       } else if(paramNameStr == VECTOR_MODE_PROP) {
1976         aListOfMap[viewIndex].insert( VECTOR_MODE_PROP, val.toInt());
1977
1978       }  else if(paramNameStr == DEFLECTION_COEFF_PROP) {
1979         aListOfMap[viewIndex].insert( DEFLECTION_COEFF_PROP, val.toDouble());
1980       }  else if(paramNameStr == MARKER_TYPE_PROP) {
1981         aListOfMap[viewIndex].insert( MARKER_TYPE_PROP, val);
1982       }
1983
1984     } // for names/parameters iterator
1985
1986     QList<SUIT_ViewManager*> lst = getApp()->viewManagers();
1987
1988     for (int index = 0; index < aListOfMap.count(); index++) {
1989
1990       appStudy->setObjectPropMap(index, entry, aListOfMap[index]);
1991
1992       //Get Visibility property of the current PropMap
1993       if (aListOfMap[index].value(VISIBILITY_PROP) == 1) {
1994         SUIT_ViewManager* vman = lst.at(index);
1995         SUIT_ViewModel* vmodel = vman->getViewModel();
1996         displayer()->Display(entry, true, dynamic_cast<SALOME_View*>(vmodel));
1997       }
1998     }
1999
2000   } // for entries iterator
2001
2002   // update all VTK and OCC views
2003   QList<SUIT_ViewManager*> lst;
2004   getApp()->viewManagers(lst);
2005   for (QList<SUIT_ViewManager*>::Iterator it = lst.begin(); it != lst.end(); it++) {
2006     SUIT_ViewModel* vmodel = (*it)->getViewModel();
2007     if (!vmodel)
2008       continue;
2009     if (vmodel->getType() == SVTK_Viewer::Type()) {
2010       SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) (*it)->getActiveView();
2011       vtkView->getRenderer()->ResetCameraClippingRange();
2012       vtkView->Repaint();
2013     }
2014     else if (vmodel->getType() == SOCC_Viewer::Type()) {
2015       //SOCC_ViewWindow* occView = (SOCC_ViewWindow*) (*it)->getActiveView();
2016       SALOME_View* occVMod = dynamic_cast<SALOME_View*>(vmodel);
2017       if (occVMod)
2018         occVMod->Repaint();
2019     }
2020   }
2021 }
2022
2023 void GeometryGUI::onViewAboutToShow()
2024 {
2025   SUIT_ViewWindow* window = application()->desktop()->activeWindow();
2026   QAction* a = action( GEOMOp::OpSwitchVectors );
2027   if ( window ) {
2028     a->setEnabled(true);
2029     bool vmode = window->property("VectorsMode").toBool();
2030     a->setText ( vmode == 1 ? tr( "MEN_VECTOR_MODE_OFF" ) : tr("MEN_VECTOR_MODE_ON") );
2031   } else {
2032     a->setText ( tr("MEN_VECTOR_MODE_ON") );
2033     a->setEnabled(false);
2034   }
2035 }
2036
2037 /*!
2038   Rename object by entry.
2039   \param entry entry of the object
2040   \param name new name of the object
2041   \brief Return \c true if rename operation finished successfully, \c false otherwise.
2042 */
2043 bool GeometryGUI::renameObject( const QString& entry, const QString& name) {
2044
2045   bool appRes = SalomeApp_Module::renameObject(entry,name);
2046   if( !appRes )
2047     return false;
2048
2049   bool result = false;
2050
2051   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication());
2052   SalomeApp_Study* appStudy = app ? dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) : 0;
2053
2054   if(!appStudy)
2055     return result;
2056
2057   _PTR(Study) aStudy = appStudy->studyDS();
2058
2059   if(!aStudy)
2060     return result;
2061
2062   _PTR(SObject) obj ( aStudy->FindObjectID(qPrintable(entry)) );
2063   _PTR(GenericAttribute) anAttr;
2064   if ( obj ) {
2065     if ( obj->FindAttribute(anAttr, "AttributeName") ) {
2066       _PTR(AttributeName) aName (anAttr);
2067
2068       GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(obj));
2069       if (!CORBA::is_nil(anObj)) {
2070         aName->SetValue( name.toLatin1().data() ); // rename the SObject
2071         anObj->SetName( name.toLatin1().data() );  // Rename the corresponding GEOM_Object
2072         result = true;
2073       }
2074     }
2075   }
2076   return result;
2077 }