1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : GeometryGUI.cxx
24 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
26 #include "GeometryGUI.h"
27 #include "GeometryGUI_Operations.h"
28 #include "GEOMGUI_OCCSelector.h"
29 #include "GEOMGUI_Selection.h"
30 #include "GEOM_Displayer.h"
31 #include "GEOM_AISShape.hxx"
33 #include "GEOM_Actor.h"
35 #include <SUIT_Desktop.h>
36 #include <SUIT_MessageBox.h>
37 #include <SUIT_ResourceMgr.h>
38 #include <SUIT_Session.h>
39 #include <SUIT_ViewManager.h>
41 #include <OCCViewer_ViewWindow.h>
42 #include <OCCViewer_ViewPort3d.h>
43 #include <OCCViewer_ViewModel.h>
44 #include <OCCViewer_ViewManager.h>
46 #include <SOCC_ViewModel.h>
47 #include <SOCC_ViewWindow.h>
49 #include <SVTK_ViewWindow.h>
50 #include <SVTK_RenderWindowInteractor.h>
51 #include <SVTK_InteractorStyle.h>
52 #include <SVTK_ViewModel.h>
54 #include <SalomeApp_Application.h>
55 #include <SalomeApp_Study.h>
57 #include <LightApp_SelectionMgr.h>
58 #include <LightApp_VTKSelector.h>
59 #include <LightApp_DataObject.h>
60 #include <LightApp_Preferences.h>
62 #include <SALOME_LifeCycleCORBA.hxx>
63 #include <SALOME_ListIO.hxx>
64 #include <SALOME_ListIteratorOfListIO.hxx>
66 #include <SALOMEDSClient_ClientFactory.hxx>
67 #include <SALOMEDSClient_IParameters.hxx>
76 #include <AIS_Drawer.hxx>
77 #include <AIS_ListOfInteractive.hxx>
78 #include <AIS_ListIteratorOfListOfInteractive.hxx>
79 #include <Prs3d_Drawer.hxx>
80 #include <Prs3d_IsoAspect.hxx>
81 #include <Aspect_TypeOfMarker.hxx>
82 #include <OSD_SharedLibrary.hxx>
83 #include <NCollection_DataMap.hxx>
84 #include <Graphic3d_HArray1OfBytes.hxx>
86 #include <utilities.h>
88 #include <vtkCamera.h>
89 #include <vtkRenderer.h>
91 #include "GEOMImpl_Types.hxx"
94 Standard_EXPORT CAM_Module* createModule() {
95 return new GeometryGUI();
99 GeometryGUI::StudyTextureMap GeometryGUI::myTextureMap;
101 GEOM::GEOM_Gen_var GeometryGUI::myComponentGeom = GEOM::GEOM_Gen::_nil();
103 GEOM::GEOM_Gen_var GeometryGUI::GetGeomGen()
105 // Bug 12290: exception in Mesh GUI on GEOMBase::GetShape() if Geometry GUI hasn't been loaded
106 if (CORBA::is_nil(myComponentGeom))
108 return GeometryGUI::myComponentGeom;
111 bool GeometryGUI::InitGeomGen()
114 if( CORBA::is_nil( myComponentGeom ) ) return false;
118 //=======================================================================
119 // function : ClientSObjectToObject
121 //=======================================================================
122 CORBA::Object_var GeometryGUI::ClientSObjectToObject (_PTR(SObject) theSObject)
124 _PTR(GenericAttribute) anAttr;
125 CORBA::Object_var anObj;
127 std::string aValue = theSObject->GetIOR();
128 if (strcmp(aValue.c_str(), "") != 0) {
129 CORBA::ORB_ptr anORB = SalomeApp_Application::orb();
130 anObj = anORB->string_to_object(aValue.c_str());
133 INFOS("ClientSObjectToObject - Unknown exception was occured!!!");
135 return anObj._retn();
138 //=======================================================================
139 // function : ClientStudyToStudy
141 //=======================================================================
142 SALOMEDS::Study_var GeometryGUI::ClientStudyToStudy (_PTR(Study) theStudy)
144 SALOME_NamingService *aNamingService = SalomeApp_Application::namingService();
145 CORBA::Object_var aSMObject = aNamingService->Resolve("/myStudyManager");
146 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(aSMObject);
147 int aStudyID = theStudy->StudyId();
148 SALOMEDS::Study_var aDSStudy = aStudyManager->GetStudyByID(aStudyID);
149 return aDSStudy._retn();
152 //=======================================================================
153 // function : GeometryGUI::GeometryGUI()
154 // purpose : Constructor
155 //=======================================================================
156 GeometryGUI::GeometryGUI() :
157 SalomeApp_Module( "GEOM" ),
158 LightApp_Module( "GEOM" )
160 if ( CORBA::is_nil( myComponentGeom ) )
162 Engines::Component_var comp = SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "GEOM" );
163 myComponentGeom = GEOM::GEOM_Gen::_narrow( comp );
166 myActiveDialogBox = 0;
168 gp_Pnt origin = gp_Pnt(0., 0., 0.);
169 gp_Dir direction = gp_Dir(0., 0., 1.);
170 myWorkingPlane = gp_Ax3(origin, direction);
173 myLocalSelectionMode = GEOM_ALLOBJECTS;
176 //=======================================================================
177 // function : GeometryGUI::~GeometryGUI()
178 // purpose : Destructor
179 //=======================================================================
180 GeometryGUI::~GeometryGUI()
182 while (!myOCCSelectors.isEmpty())
183 delete myOCCSelectors.takeFirst();
185 while (!myVTKSelectors.isEmpty())
186 delete myVTKSelectors.takeFirst();
188 qDeleteAll(myGUIMap);
191 //=======================================================================
192 // function : GeometryGUI::getLibrary()
193 // purpose : get or load GUI library by name [ internal ]
194 //=======================================================================
195 typedef GEOMGUI* (*LibraryGUI)( GeometryGUI* );
196 GEOMGUI* GeometryGUI::getLibrary( const QString& libraryName )
198 if ( !myGUIMap.contains( libraryName ) ) {
199 // try to load library if it is not loaded yet
201 QString dirs = getenv( "LD_LIBRARY_PATH" );
204 QString dirs = getenv( "PATH" );
207 if ( !dirs.isEmpty() ) {
208 QStringList dirList = dirs.split(sep, QString::SkipEmptyParts ); // skip empty entries
209 QListIterator<QString> it( dirList ); it.toBack();
210 while ( it.hasPrevious() ) {
211 QFileInfo fi( Qtx::addSlash( it.previous() ) + libraryName );
213 OSD_SharedLibrary aSharedLibrary( fi.fileName().toLatin1().constData() );
214 bool res = aSharedLibrary.DlOpen( OSD_RTLD_LAZY );
216 MESSAGE( "Can't open library : " << aSharedLibrary.DlError() );
217 continue; // continue search further
219 OSD_Function osdF = aSharedLibrary.DlSymb( "GetLibGUI" );
220 if ( osdF != NULL ) {
221 LibraryGUI func = (GEOMGUI* (*) (GeometryGUI*))osdF;
222 GEOMGUI* libGUI = (*func)( this );
224 myGUIMap[ libraryName ] = libGUI;
225 break; // found and loaded!
232 return myGUIMap.contains( libraryName ) ? myGUIMap[ libraryName ] : 0;
235 //=======================================================================
236 // function : GeometryGUI::ActiveWorkingPlane()
237 // purpose : Activate Working Plane View
238 //=======================================================================
239 void GeometryGUI::ActiveWorkingPlane()
241 gp_Dir DZ = myWorkingPlane.Direction();
242 gp_Dir DY = myWorkingPlane.YDirection();
244 SUIT_ViewWindow* window = application()->desktop()->activeWindow();
245 bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
246 bool ViewVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
249 OCCViewer_ViewWindow* vw = dynamic_cast<OCCViewer_ViewWindow*>( window );
251 Handle(V3d_View) view3d = vw->getViewPort()->getView();
253 view3d->SetProj(DZ.X(), DZ.Y(), DZ.Z());
254 view3d->SetUp(DY.X(), DY.Y(), DY.Z());
260 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( window );
262 vtkCamera* camera = vw->getRenderer()->GetActiveCamera();
264 camera->SetPosition(DZ.X(), DZ.Y(), DZ.Z());
265 camera->SetViewUp(DY.X(), DY.Y(), DY.Z());
266 camera->SetFocalPoint(0,0,0);
273 //=======================================================================
274 // function : GeometryGUI::SetActiveDialogBox()
275 // purpose : Set active dialog box
276 //=======================================================================
277 void GeometryGUI::SetActiveDialogBox( QDialog* aDlg )
279 myActiveDialogBox = (QDialog*)aDlg;
282 //=======================================================================
283 // function : GeometryGUI::EmitSignalDeactivateDialog()
284 // purpose : Emit a signal to deactivate the active dialog Box
285 //=======================================================================
286 void GeometryGUI::EmitSignalDeactivateDialog()
288 emit SignalDeactivateActiveDialog();
291 //=======================================================================
292 // function : GeometryGUI::EmitSignalCloseAllDialogs()
293 // purpose : Emit a signal to close all non modal dialogs box
294 //=======================================================================
295 void GeometryGUI::EmitSignalCloseAllDialogs()
297 emit SignalCloseAllDialogs();
300 //=======================================================================
301 // function : GeometryGUI::EmitSignalDefaultStepValueChanged()
302 // purpose : Emit a signal to inform that default real spin box step has
304 //=======================================================================
305 void GeometryGUI::EmitSignalDefaultStepValueChanged(double newVal)
307 emit SignalDefaultStepValueChanged(newVal);
310 //=======================================================================
311 // function : GeometryGUI::OnGUIEvent()
312 // purpose : common slot for all menu/toolbar actions
313 //=======================================================================
314 void GeometryGUI::OnGUIEvent()
316 const QObject* obj = sender();
317 if ( !obj || !obj->inherits( "QAction" ) )
319 int id = actionId((QAction*)obj);
324 //=======================================================================
325 // function : GeometryGUI::OnGUIEvent()
326 // purpose : manage all events on GUI [static]
327 //=======================================================================
328 void GeometryGUI::OnGUIEvent( int id )
330 SUIT_Application* anApp = application();
332 SUIT_Desktop* desk = anApp->desktop();
334 // check type of the active viewframe
335 SUIT_ViewWindow* window = desk->activeWindow();
336 bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
337 bool ViewVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
338 // if current viewframe is not of OCC and not of VTK type - return immediately
339 // fix for IPAL8958 - allow some commands to execute even when NO viewer is active (rename for example)
340 QList<int> NotViewerDependentCommands;
341 NotViewerDependentCommands << GEOMOp::OpRename
344 << GEOMOp::OpShowOnly
345 << GEOMOp::OpShowChildren
346 << GEOMOp::OpHideChildren
347 << GEOMOp::OpPointMarker;
348 if ( !ViewOCC && !ViewVTK && !NotViewerDependentCommands.contains( id ) )
351 // fix for IPAL9103, point 2
352 if ( CORBA::is_nil( GetGeomGen() ) ) {
353 SUIT_MessageBox::critical( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_GET_ENGINE" ), tr( "GEOM_BUT_OK" ) );
358 // find corresponding GUI library
360 case GEOMOp::OpImport: // MENU FILE - IMPORT
361 case GEOMOp::OpExport: // MENU FILE - EXPORT
362 case GEOMOp::OpSelectVertex: // POPUP MENU - SELECT ONLY - VERTEX
363 case GEOMOp::OpSelectEdge: // POPUP MENU - SELECT ONLY - EDGE
364 case GEOMOp::OpSelectWire: // POPUP MENU - SELECT ONLY - WIRE
365 case GEOMOp::OpSelectFace: // POPUP MENU - SELECT ONLY - FACE
366 case GEOMOp::OpSelectShell: // POPUP MENU - SELECT ONLY - SHELL
367 case GEOMOp::OpSelectSolid: // POPUP MENU - SELECT ONLY - SOLID
368 case GEOMOp::OpSelectCompound: // POPUP MENU - SELECT ONLY - COMPOUND
369 case GEOMOp::OpSelectAll: // POPUP MENU - SELECT ONLY - SELECT ALL
370 case GEOMOp::OpDelete: // MENU EDIT - DELETE
371 case GEOMOp::OpCheckGeom: // MENU TOOLS - CHECK GEOMETRY
372 case GEOMOp::OpDeflection: // POPUP MENU - DEFLECTION COEFFICIENT
373 case GEOMOp::OpColor: // POPUP MENU - COLOR
374 case GEOMOp::OpTransparency: // POPUP MENU - TRANSPARENCY
375 case GEOMOp::OpIsos: // POPUP MENU - ISOS
376 case GEOMOp::OpAutoColor: // POPUP MENU - AUTO COLOR
377 case GEOMOp::OpNoAutoColor: // POPUP MENU - DISABLE AUTO COLOR
378 case GEOMOp::OpShowChildren: // POPUP MENU - SHOW CHILDREN
379 case GEOMOp::OpHideChildren: // POPUP MENU - HIDE CHILDREN
380 case GEOMOp::OpPointMarker: // POPUP MENU - POINT MARKER
381 case GEOMOp::OpRename: // POPUP MENU - RENAME
382 libName = "GEOMToolsGUI";
384 case GEOMOp::OpDisplayMode: // MENU VIEW - WIREFRAME/SHADING
385 case GEOMOp::OpShowAll: // MENU VIEW - SHOW ALL
386 case GEOMOp::OpShowOnly: // MENU VIEW - DISPLAY ONLY
387 case GEOMOp::OpHideAll: // MENU VIEW - ERASE ALL
388 case GEOMOp::OpHide: // MENU VIEW - ERASE
389 case GEOMOp::OpShow: // MENU VIEW - DISPLAY
390 case GEOMOp::OpSwitchVectors: // MENU VIEW - VECTOR MODE
391 case GEOMOp::OpWireframe: // POPUP MENU - WIREFRAME
392 case GEOMOp::OpShading: // POPUP MENU - SHADING
393 case GEOMOp::OpVectors: // POPUP MENU - VECTORS
394 libName = "DisplayGUI";
396 case GEOMOp::OpPoint: // MENU BASIC - POINT
397 case GEOMOp::OpLine: // MENU BASIC - LINE
398 case GEOMOp::OpCircle: // MENU BASIC - CIRCLE
399 case GEOMOp::OpEllipse: // MENU BASIC - ELLIPSE
400 case GEOMOp::OpArc: // MENU BASIC - ARC
401 case GEOMOp::OpVector: // MENU BASIC - VECTOR
402 case GEOMOp::OpPlane: // MENU BASIC - PLANE
403 case GEOMOp::OpCurve: // MENU BASIC - CURVE
404 case GEOMOp::OpLCS: // MENU BASIC - REPAIR
405 libName = "BasicGUI";
407 case GEOMOp::OpBox: // MENU PRIMITIVE - BOX
408 case GEOMOp::OpCylinder: // MENU PRIMITIVE - CYLINDER
409 case GEOMOp::OpSphere: // MENU PRIMITIVE - SPHERE
410 case GEOMOp::OpTorus: // MENU PRIMITIVE - TORUS
411 case GEOMOp::OpCone: // MENU PRIMITIVE - CONE
412 case GEOMOp::OpRectangle: // MENU PRIMITIVE - FACE
413 case GEOMOp::OpDisk: // MENU PRIMITIVE - DISK
414 libName = "PrimitiveGUI";
416 case GEOMOp::OpPrism: // MENU GENERATION - PRISM
417 case GEOMOp::OpRevolution: // MENU GENERATION - REVOLUTION
418 case GEOMOp::OpFilling: // MENU GENERATION - FILLING
419 case GEOMOp::OpPipe: // MENU GENERATION - PIPE
420 libName = "GenerationGUI";
422 case GEOMOp::Op2dSketcher: // MENU ENTITY - SKETCHER
423 case GEOMOp::Op3dSketcher: // MENU ENTITY - 3D SKETCHER
424 case GEOMOp::OpExplode: // MENU ENTITY - EXPLODE
425 libName = "EntityGUI";
427 case GEOMOp::OpEdge: // MENU BUILD - EDGE
428 case GEOMOp::OpWire: // MENU BUILD - WIRE
429 case GEOMOp::OpFace: // MENU BUILD - FACE
430 case GEOMOp::OpShell: // MENU BUILD - SHELL
431 case GEOMOp::OpSolid: // MENU BUILD - SOLID
432 case GEOMOp::OpCompound: // MENU BUILD - COMPUND
433 libName = "BuildGUI";
435 case GEOMOp::OpFuse: // MENU BOOLEAN - FUSE
436 case GEOMOp::OpCommon: // MENU BOOLEAN - COMMON
437 case GEOMOp::OpCut: // MENU BOOLEAN - CUT
438 case GEOMOp::OpSection: // MENU BOOLEAN - SECTION
439 libName = "BooleanGUI";
441 case GEOMOp::OpTranslate: // MENU TRANSFORMATION - TRANSLATION
442 case GEOMOp::OpRotate: // MENU TRANSFORMATION - ROTATION
443 case GEOMOp::OpChangeLoc: // MENU TRANSFORMATION - LOCATION
444 case GEOMOp::OpMirror: // MENU TRANSFORMATION - MIRROR
445 case GEOMOp::OpScale: // MENU TRANSFORMATION - SCALE
446 case GEOMOp::OpOffset: // MENU TRANSFORMATION - OFFSET
447 case GEOMOp::OpMultiTranslate: // MENU TRANSFORMATION - MULTI-TRANSLATION
448 case GEOMOp::OpMultiRotate: // MENU TRANSFORMATION - MULTI-ROTATION
449 case GEOMOp::OpReimport: // CONTEXT(POPUP) MENU - RELOAD_IMPORTED
450 libName = "TransformationGUI";
452 case GEOMOp::OpPartition: // MENU OPERATION - PARTITION
453 case GEOMOp::OpArchimede: // MENU OPERATION - ARCHIMEDE
454 case GEOMOp::OpFillet3d: // MENU OPERATION - FILLET
455 case GEOMOp::OpChamfer: // MENU OPERATION - CHAMFER
456 case GEOMOp::OpClipping: // MENU OPERATION - CLIPPING RANGE
457 case GEOMOp::OpShapesOnShape: // MENU OPERATION - GET SHAPES ON SHAPE
458 case GEOMOp::OpFillet2d: // MENU OPERATION - FILLET 2D
459 case GEOMOp::OpFillet1d: // MENU OPERATION - FILLET 1D
460 libName = "OperationGUI";
462 case GEOMOp::OpSewing: // MENU REPAIR - SEWING
463 case GEOMOp::OpSuppressFaces: // MENU REPAIR - SUPPRESS FACES
464 case GEOMOp::OpSuppressHoles: // MENU REPAIR - SUPPRESS HOLE
465 case GEOMOp::OpShapeProcess: // MENU REPAIR - SHAPE PROCESSING
466 case GEOMOp::OpCloseContour: // MENU REPAIR - CLOSE CONTOUR
467 case GEOMOp::OpRemoveIntWires: // MENU REPAIR - REMOVE INTERNAL WIRES
468 case GEOMOp::OpAddPointOnEdge: // MENU REPAIR - ADD POINT ON EDGE
469 case GEOMOp::OpFreeBoundaries: // MENU MEASURE - FREE BOUNDARIES
470 case GEOMOp::OpFreeFaces: // MENU MEASURE - FREE FACES
471 case GEOMOp::OpOrientation: // MENU REPAIR - CHANGE ORIENTATION
472 case GEOMOp::OpGlueFaces: // MENU REPAIR - GLUE FACES
473 case GEOMOp::OpRemoveExtraEdges: // MENU REPAIR - REMOVE EXTRA EDGES
474 libName = "RepairGUI";
476 case GEOMOp::OpProperties: // MENU MEASURE - PROPERTIES
477 case GEOMOp::OpCenterMass: // MENU MEASURE - CDG
478 case GEOMOp::OpInertia: // MENU MEASURE - INERTIA
479 case GEOMOp::OpNormale: // MENU MEASURE - NORMALE
480 case GEOMOp::OpBoundingBox: // MENU MEASURE - BOUNDING BOX
481 case GEOMOp::OpMinDistance: // MENU MEASURE - MIN DISTANCE
482 case GEOMOp::OpAngle: // MENU MEASURE - ANGLE
483 case GEOMOp::OpTolerance: // MENU MEASURE - TOLERANCE
484 case GEOMOp::OpWhatIs: // MENU MEASURE - WHATIS
485 case GEOMOp::OpCheckShape: // MENU MEASURE - CHECK
486 case GEOMOp::OpCheckCompound: // MENU MEASURE - CHECK COMPOUND OF BLOCKS
487 case GEOMOp::OpPointCoordinates: // MENU MEASURE - POINT COORDINATES
488 libName = "MeasureGUI";
490 case GEOMOp::OpGroupCreate: // MENU GROUP - CREATE
491 case GEOMOp::OpGroupCreatePopup: // POPUP MENU - CREATE GROUP
492 case GEOMOp::OpGroupEdit: // MENU GROUP - EDIT
493 libName = "GroupGUI";
495 case GEOMOp::OpHexaSolid: // MENU BLOCKS - HEXAHEDRAL SOLID
496 case GEOMOp::OpMultiTransform: // MENU BLOCKS - MULTI-TRANSFORMATION
497 case GEOMOp::OpQuadFace: // MENU BLOCKS - QUADRANGLE FACE
498 case GEOMOp::OpPropagate: // MENU BLOCKS - PROPAGATE
499 case GEOMOp::OpExplodeBlock: // MENU BLOCKS - EXPLODE ON BLOCKS
500 libName = "BlocksGUI";
502 case GEOMOp::OpAdvancedNoOp: // NO OPERATION (advanced operations base)
503 //@@ insert new functions before this line @@//
504 libName = "AdvancedGUI";
510 GEOMGUI* library = 0;
511 if ( !libName.isEmpty() ) {
513 libName = QString( "lib" ) + libName + ".so";
515 libName = libName + ".dll";
517 library = getLibrary( libName );
520 // call method of corresponding GUI library
522 library->OnGUIEvent( id, desk );
524 SUIT_MessageBox::critical( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_LIB_NOT_FOUND" ), tr( "GEOM_BUT_OK" ) );
527 //=================================================================================
528 // function : GeometryGUI::OnKeyPress()
529 // purpose : Called when any key is pressed by user [static]
530 //=================================================================================
531 void GeometryGUI::OnKeyPress( SUIT_ViewWindow* w, QKeyEvent* e )
533 if ( !application() )
535 foreach ( GEOMGUI* lib, myGUIMap )
536 lib->OnKeyPress( e, application()->desktop(), w );
539 //=================================================================================
540 // function : GeometryGUI::OnMouseMove()
541 // purpose : Manages mouse move events [static]
542 //=================================================================================
543 void GeometryGUI::OnMouseMove( SUIT_ViewWindow* w, QMouseEvent* e )
545 if ( !application() )
547 foreach ( GEOMGUI* lib, myGUIMap )
548 lib->OnMouseMove( e, application()->desktop(), w );
551 //=================================================================================
552 // function : GeometryGUI::OnMousePress()
553 // purpose : Manage mouse press events [static]
554 //=================================================================================
555 void GeometryGUI::OnMousePress( SUIT_ViewWindow* w, QMouseEvent* e )
557 if ( !application() )
559 foreach ( GEOMGUI* lib, myGUIMap )
560 lib->OnMousePress( e, application()->desktop(), w );
563 //=======================================================================
564 // function : createGeomAction
566 //=======================================================================
567 void GeometryGUI::createGeomAction( const int id, const QString& label, const QString& icolabel, const int accel, const bool toggle )
569 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
570 QPixmap icon = icolabel.isEmpty() ? resMgr->loadPixmap( "GEOM", tr( (QString( "ICO_" )+label).toLatin1().constData() ), false )
571 : resMgr->loadPixmap( "GEOM", tr( icolabel.toLatin1().constData() ) );
573 tr( QString( "TOP_%1" ).arg( label ).toLatin1().constData() ),
575 tr( QString( "MEN_%1" ).arg( label ).toLatin1().constData() ),
576 tr( QString( "STB_%1" ).arg( label ).toLatin1().constData() ),
578 application()->desktop(),
580 this, SLOT( OnGUIEvent() ) );
585 //=======================================================================
586 // function : GeometryGUI::initialize()
587 // purpose : Called when GEOM module is created
588 //=======================================================================
589 void GeometryGUI::initialize( CAM_Application* app )
591 SalomeApp_Module::initialize( app );
593 // ----- create actions --------------
595 createGeomAction( GEOMOp::OpImport, "IMPORT", "", Qt::ControlModifier + Qt::Key_I );
596 createGeomAction( GEOMOp::OpExport, "EXPORT", "", Qt::ControlModifier + Qt::Key_E );
598 createGeomAction( GEOMOp::OpDelete, "DELETE", "", Qt::Key_Delete );
600 createGeomAction( GEOMOp::OpPoint, "POINT" );
601 createGeomAction( GEOMOp::OpLine, "LINE" );
602 createGeomAction( GEOMOp::OpCircle, "CIRCLE" );
603 createGeomAction( GEOMOp::OpEllipse, "ELLIPSE" );
604 createGeomAction( GEOMOp::OpArc, "ARC" );
605 createGeomAction( GEOMOp::OpCurve, "CURVE" );
606 createGeomAction( GEOMOp::OpVector, "VECTOR" );
607 createGeomAction( GEOMOp::OpPlane, "PLANE" );
608 createGeomAction( GEOMOp::OpLCS, "LOCAL_CS" );
610 createGeomAction( GEOMOp::OpBox, "BOX" );
611 createGeomAction( GEOMOp::OpCylinder, "CYLINDER" );
612 createGeomAction( GEOMOp::OpSphere, "SPHERE" );
613 createGeomAction( GEOMOp::OpTorus, "TORUS" );
614 createGeomAction( GEOMOp::OpCone, "CONE" );
615 createGeomAction( GEOMOp::OpRectangle, "RECTANGLE" );
616 createGeomAction( GEOMOp::OpDisk, "DISK" );
618 createGeomAction( GEOMOp::OpPrism, "EXTRUSION" );
619 createGeomAction( GEOMOp::OpRevolution, "REVOLUTION" );
620 createGeomAction( GEOMOp::OpFilling, "FILLING" );
621 createGeomAction( GEOMOp::OpPipe, "PIPE" );
623 createGeomAction( GEOMOp::OpGroupCreate, "GROUP_CREATE" );
624 createGeomAction( GEOMOp::OpGroupEdit, "GROUP_EDIT" );
626 createGeomAction( GEOMOp::OpReimport, "RELOAD_IMPORTED" );
628 createGeomAction( GEOMOp::OpQuadFace, "Q_FACE" );
629 createGeomAction( GEOMOp::OpHexaSolid, "HEX_SOLID" );
631 createGeomAction( GEOMOp::Op2dSketcher, "SKETCH" );
632 createGeomAction( GEOMOp::Op3dSketcher, "3DSKETCH" );
633 createGeomAction( GEOMOp::OpExplode, "EXPLODE" );
635 createGeomAction( GEOMOp::OpEdge, "EDGE" );
636 createGeomAction( GEOMOp::OpWire, "WIRE" );
637 createGeomAction( GEOMOp::OpFace, "FACE" );
638 createGeomAction( GEOMOp::OpShell, "SHELL" );
639 createGeomAction( GEOMOp::OpSolid, "SOLID" );
640 createGeomAction( GEOMOp::OpCompound, "COMPOUND" );
642 createGeomAction( GEOMOp::OpFuse, "FUSE" );
643 createGeomAction( GEOMOp::OpCommon, "COMMON" );
644 createGeomAction( GEOMOp::OpCut, "CUT" );
645 createGeomAction( GEOMOp::OpSection, "SECTION" );
647 createGeomAction( GEOMOp::OpTranslate, "TRANSLATION" );
648 createGeomAction( GEOMOp::OpRotate, "ROTATION" );
649 createGeomAction( GEOMOp::OpChangeLoc, "MODIFY_LOCATION" );
650 createGeomAction( GEOMOp::OpMirror, "MIRROR" );
651 createGeomAction( GEOMOp::OpScale, "SCALE" );
652 createGeomAction( GEOMOp::OpOffset, "OFFSET" );
653 createGeomAction( GEOMOp::OpMultiTranslate, "MUL_TRANSLATION" );
654 createGeomAction( GEOMOp::OpMultiRotate, "MUL_ROTATION" );
656 createGeomAction( GEOMOp::OpPartition, "PARTITION" );
657 createGeomAction( GEOMOp::OpArchimede, "ARCHIMEDE" );
658 createGeomAction( GEOMOp::OpFillet3d, "FILLET" );
659 createGeomAction( GEOMOp::OpChamfer, "CHAMFER" );
660 //createGeomAction( GEOMOp::OpClipping, "CLIPPING" );
661 createGeomAction( GEOMOp::OpShapesOnShape, "GET_SHAPES_ON_SHAPES" );
662 createGeomAction( GEOMOp::OpFillet1d, "FILLET_1D" );
663 createGeomAction( GEOMOp::OpFillet2d, "FILLET_2D" );
665 createGeomAction( GEOMOp::OpMultiTransform, "MUL_TRANSFORM" );
666 createGeomAction( GEOMOp::OpExplodeBlock, "EXPLODE_BLOCKS" );
667 createGeomAction( GEOMOp::OpPropagate, "PROPAGATE" );
669 createGeomAction( GEOMOp::OpSewing, "SEWING" );
670 createGeomAction( GEOMOp::OpGlueFaces, "GLUE_FACES" );
671 createGeomAction( GEOMOp::OpSuppressFaces, "SUPPRESS_FACES" );
672 createGeomAction( GEOMOp::OpSuppressHoles, "SUPPERSS_HOLES" );
673 createGeomAction( GEOMOp::OpShapeProcess, "SHAPE_PROCESS" );
674 createGeomAction( GEOMOp::OpCloseContour, "CLOSE_CONTOUR" );
675 createGeomAction( GEOMOp::OpRemoveIntWires, "SUPPRESS_INT_WIRES" );
676 createGeomAction( GEOMOp::OpAddPointOnEdge, "POINT_ON_EDGE" );
677 createGeomAction( GEOMOp::OpFreeBoundaries, "CHECK_FREE_BNDS" );
678 createGeomAction( GEOMOp::OpFreeFaces, "CHECK_FREE_FACES" );
679 createGeomAction( GEOMOp::OpOrientation, "CHANGE_ORIENTATION" );
680 createGeomAction( GEOMOp::OpRemoveExtraEdges, "REMOVE_EXTRA_EDGES" );
682 createGeomAction( GEOMOp::OpPointCoordinates, "POINT_COORDS" );
683 createGeomAction( GEOMOp::OpProperties, "BASIC_PROPS" );
684 createGeomAction( GEOMOp::OpCenterMass, "MASS_CENTER" );
685 createGeomAction( GEOMOp::OpInertia, "INERTIA" );
686 createGeomAction( GEOMOp::OpNormale, "NORMALE" );
687 createGeomAction( GEOMOp::OpBoundingBox, "BND_BOX" );
688 createGeomAction( GEOMOp::OpMinDistance, "MIN_DIST" );
689 createGeomAction( GEOMOp::OpAngle, "MEASURE_ANGLE" );
691 createGeomAction( GEOMOp::OpTolerance, "TOLERANCE" );
692 createGeomAction( GEOMOp::OpWhatIs, "WHAT_IS" );
693 createGeomAction( GEOMOp::OpCheckShape, "CHECK" );
694 createGeomAction( GEOMOp::OpCheckCompound, "CHECK_COMPOUND" );
696 #ifdef _DEBUG_ // PAL16821
697 createGeomAction( GEOMOp::OpCheckGeom, "CHECK_GEOMETRY" );
700 createGeomAction( GEOMOp::OpDisplayMode, "SHADING" );
701 createGeomAction( GEOMOp::OpShowAll, "DISPLAY_ALL" );
702 createGeomAction( GEOMOp::OpHideAll, "ERASE_ALL" );
703 createGeomAction( GEOMOp::OpShow, "DISPLAY" );
704 createGeomAction( GEOMOp::OpSwitchVectors, "VECTOR_MODE");
705 createGeomAction( GEOMOp::OpSelectVertex, "VERTEX_SEL_ONLY" ,"", 0, true );
706 createGeomAction( GEOMOp::OpSelectEdge, "EDGE_SEL_ONLY", "", 0, true );
707 createGeomAction( GEOMOp::OpSelectWire, "WIRE_SEL_ONLY", "", 0, true );
708 createGeomAction( GEOMOp::OpSelectFace, "FACE_SEL_ONLY", "", 0, true );
709 createGeomAction( GEOMOp::OpSelectShell, "SHELL_SEL_ONLY", "", 0, true );
710 createGeomAction( GEOMOp::OpSelectSolid, "SOLID_SEL_ONLY", "", 0, true );
711 createGeomAction( GEOMOp::OpSelectCompound, "COMPOUND_SEL_ONLY", "", 0, true );
712 createGeomAction( GEOMOp::OpSelectAll, "ALL_SEL_ONLY", "", 0, true );
713 createGeomAction( GEOMOp::OpShowOnly, "DISPLAY_ONLY" );
714 createGeomAction( GEOMOp::OpHide, "ERASE" );
716 createGeomAction( GEOMOp::OpRename, "POP_RENAME", "", Qt::Key_F2 );
717 createGeomAction( GEOMOp::OpWireframe, "POP_WIREFRAME", "", 0, true );
718 createGeomAction( GEOMOp::OpShading, "POP_SHADING", "", 0, true );
719 createGeomAction( GEOMOp::OpVectors, "POP_VECTORS", "", 0, true );
720 createGeomAction( GEOMOp::OpDeflection, "POP_DEFLECTION" );
721 createGeomAction( GEOMOp::OpColor, "POP_COLOR" );
722 createGeomAction( GEOMOp::OpTransparency, "POP_TRANSPARENCY" );
723 createGeomAction( GEOMOp::OpIsos, "POP_ISOS" );
724 createGeomAction( GEOMOp::OpAutoColor, "POP_AUTO_COLOR" );
725 createGeomAction( GEOMOp::OpNoAutoColor, "POP_DISABLE_AUTO_COLOR" );
726 createGeomAction( GEOMOp::OpGroupCreatePopup, "POP_CREATE_GROUP" );
727 createGeomAction( GEOMOp::OpShowChildren, "POP_SHOW_CHILDREN" );
728 createGeomAction( GEOMOp::OpHideChildren, "POP_HIDE_CHILDREN" );
729 createGeomAction( GEOMOp::OpPointMarker, "POP_POINT_MARKER" );
731 //@@ insert new functions before this line @@//
733 // ---- create menus --------------------------
735 int fileId = createMenu( tr( "MEN_FILE" ), -1, -1 );
736 createMenu( separator(), fileId, 10 );
737 createMenu( GEOMOp::OpImport, fileId, 10 );
738 createMenu( GEOMOp::OpExport, fileId, 10 );
739 createMenu( separator(), fileId, -1 );
741 int editId = createMenu( tr( "MEN_EDIT" ), -1, -1 );
742 createMenu( GEOMOp::OpDelete, editId, -1 );
744 int newEntId = createMenu( tr( "MEN_NEW_ENTITY" ), -1, -1, 10 );
746 int basicId = createMenu( tr( "MEN_BASIC" ), newEntId, -1 );
747 createMenu( GEOMOp::OpPoint, basicId, -1 );
748 createMenu( GEOMOp::OpLine, basicId, -1 );
749 createMenu( GEOMOp::OpCircle, basicId, -1 );
750 createMenu( GEOMOp::OpEllipse, basicId, -1 );
751 createMenu( GEOMOp::OpArc, basicId, -1 );
752 createMenu( GEOMOp::OpCurve, basicId, -1 );
753 createMenu( separator(), basicId, -1 );
754 createMenu( GEOMOp::OpVector, basicId, -1 );
755 createMenu( GEOMOp::OpPlane, basicId, -1 );
756 createMenu( GEOMOp::OpLCS, basicId, -1 );
758 int primId = createMenu( tr( "MEN_PRIMITIVES" ), newEntId, -1 );
759 createMenu( GEOMOp::OpBox, primId, -1 );
760 createMenu( GEOMOp::OpCylinder, primId, -1 );
761 createMenu( GEOMOp::OpSphere, primId, -1 );
762 createMenu( GEOMOp::OpTorus, primId, -1 );
763 createMenu( GEOMOp::OpCone, primId, -1 );
764 createMenu( GEOMOp::OpRectangle, primId, -1 );
765 createMenu( GEOMOp::OpDisk, primId, -1 );
767 int genId = createMenu( tr( "MEN_GENERATION" ), newEntId, -1 );
768 createMenu( GEOMOp::OpPrism, genId, -1 );
769 createMenu( GEOMOp::OpRevolution, genId, -1 );
770 createMenu( GEOMOp::OpFilling, genId, -1 );
771 createMenu( GEOMOp::OpPipe, genId, -1 );
773 int advId = createMenu( tr( "MEN_ADVANCED" ), newEntId, -1 );
774 //@@ insert new functions before this line @@//
776 createMenu( separator(), newEntId, -1 );
778 int groupId = createMenu( tr( "MEN_GROUP" ), newEntId, -1 );
779 createMenu( GEOMOp::OpGroupCreate, groupId, -1 );
780 createMenu( GEOMOp::OpGroupEdit, groupId, -1 );
782 createMenu( separator(), newEntId, -1 );
784 int blocksId = createMenu( tr( "MEN_BLOCKS" ), newEntId, -1 );
785 createMenu( GEOMOp::OpQuadFace, blocksId, -1 );
786 createMenu( GEOMOp::OpHexaSolid, blocksId, -1 );
788 createMenu( separator(), newEntId, -1 );
790 createMenu( GEOMOp::Op2dSketcher, newEntId, -1 );
791 createMenu( GEOMOp::Op3dSketcher, newEntId, -1 );
793 createMenu( separator(), newEntId, -1 );
795 createMenu( GEOMOp::OpExplode, newEntId, -1 );
797 int buildId = createMenu( tr( "MEN_BUILD" ), newEntId, -1 );
798 createMenu( GEOMOp::OpEdge, buildId, -1 );
799 createMenu( GEOMOp::OpWire, buildId, -1 );
800 createMenu( GEOMOp::OpFace, buildId, -1 );
801 createMenu( GEOMOp::OpShell, buildId, -1 );
802 createMenu( GEOMOp::OpSolid, buildId, -1 );
803 createMenu( GEOMOp::OpCompound, buildId, -1 );
805 int operId = createMenu( tr( "MEN_OPERATIONS" ), -1, -1, 10 );
807 int boolId = createMenu( tr( "MEN_BOOLEAN" ), operId, -1 );
808 createMenu( GEOMOp::OpFuse, boolId, -1 );
809 createMenu( GEOMOp::OpCommon, boolId, -1 );
810 createMenu( GEOMOp::OpCut, boolId, -1 );
811 createMenu( GEOMOp::OpSection, boolId, -1 );
813 int transId = createMenu( tr( "MEN_TRANSFORMATION" ), operId, -1 );
814 createMenu( GEOMOp::OpTranslate, transId, -1 );
815 createMenu( GEOMOp::OpRotate, transId, -1 );
816 createMenu( GEOMOp::OpChangeLoc, transId, -1 );
817 createMenu( GEOMOp::OpMirror, transId, -1 );
818 createMenu( GEOMOp::OpScale, transId, -1 );
819 createMenu( GEOMOp::OpOffset, transId, -1 );
820 createMenu( separator(), transId, -1 );
821 createMenu( GEOMOp::OpMultiTranslate, transId, -1 );
822 createMenu( GEOMOp::OpMultiRotate, transId, -1 );
824 int blockId = createMenu( tr( "MEN_BLOCKS" ), operId, -1 );
825 createMenu( GEOMOp::OpMultiTransform, blockId, -1 );
826 createMenu( GEOMOp::OpExplodeBlock, blockId, -1 );
827 createMenu( GEOMOp::OpPropagate, blockId, -1 );
829 createMenu( separator(), operId, -1 );
831 createMenu( GEOMOp::OpPartition, operId, -1 );
832 createMenu( GEOMOp::OpArchimede, operId, -1 );
833 createMenu( GEOMOp::OpShapesOnShape, operId, -1 );
835 createMenu( separator(), operId, -1 );
837 createMenu( GEOMOp::OpFillet1d, operId, -1 );
838 createMenu( GEOMOp::OpFillet2d, operId, -1 );
839 createMenu( GEOMOp::OpFillet3d, operId, -1 );
840 createMenu( GEOMOp::OpChamfer, operId, -1 );
841 //createMenu( GEOMOp::OpClipping, operId, -1 );
843 int repairId = createMenu( tr( "MEN_REPAIR" ), -1, -1, 10 );
844 createMenu( GEOMOp::OpShapeProcess, repairId, -1 );
845 createMenu( GEOMOp::OpSuppressFaces, repairId, -1 );
846 createMenu( GEOMOp::OpCloseContour, repairId, -1 );
847 createMenu( GEOMOp::OpRemoveIntWires, repairId, -1 );
848 createMenu( GEOMOp::OpSuppressHoles, repairId, -1 );
849 createMenu( GEOMOp::OpSewing, repairId, -1 );
850 createMenu( GEOMOp::OpGlueFaces, repairId, -1 );
851 createMenu( GEOMOp::OpAddPointOnEdge, repairId, -1 );
852 //createMenu( GEOMOp::OpFreeBoundaries, repairId, -1 );
853 //createMenu( GEOMOp::OpFreeFaces, repairId, -1 );
854 createMenu( GEOMOp::OpOrientation, repairId, -1 );
855 createMenu( GEOMOp::OpRemoveExtraEdges, repairId, -1 );
857 int measurId = createMenu( tr( "MEN_MEASURES" ), -1, -1, 10 );
858 createMenu( GEOMOp::OpPointCoordinates, measurId, -1 );
859 createMenu( GEOMOp::OpProperties, measurId, -1 );
860 createMenu( separator(), measurId, -1 );
861 createMenu( GEOMOp::OpCenterMass, measurId, -1 );
862 createMenu( GEOMOp::OpInertia, measurId, -1 );
863 createMenu( GEOMOp::OpNormale, measurId, -1 );
864 createMenu( separator(), measurId, -1 );
865 createMenu( GEOMOp::OpFreeBoundaries, measurId, -1 );
866 createMenu( GEOMOp::OpFreeFaces, measurId, -1 );
867 createMenu( separator(), measurId, -1 );
869 int dimId = createMenu( tr( "MEN_DIMENSIONS" ), measurId, -1 );
870 createMenu( GEOMOp::OpBoundingBox, dimId, -1 );
871 createMenu( GEOMOp::OpMinDistance, dimId, -1 );
872 createMenu( GEOMOp::OpAngle, dimId, -1 );
874 createMenu( separator(), measurId, -1 );
875 createMenu( GEOMOp::OpTolerance, measurId, -1 );
876 createMenu( separator(), measurId, -1 );
877 createMenu( GEOMOp::OpWhatIs, measurId, -1 );
878 createMenu( GEOMOp::OpCheckShape, measurId, -1 );
879 createMenu( GEOMOp::OpCheckCompound, measurId, -1 );
881 #ifdef _DEBUG_ // PAL16821
882 int toolsId = createMenu( tr( "MEN_TOOLS" ), -1, -1, 50 );
883 createMenu( separator(), toolsId, -1 );
884 createMenu( GEOMOp::OpCheckGeom, toolsId, -1 );
887 int viewId = createMenu( tr( "MEN_VIEW" ), -1, -1 );
888 createMenu( separator(), viewId, -1 );
890 int dispmodeId = createMenu( tr( "MEN_DISPLAY_MODE" ), viewId, -1 );
891 createMenu( GEOMOp::OpDisplayMode, dispmodeId, -1 );
892 createMenu( separator(), dispmodeId, -1 );
893 createMenu( GEOMOp::OpSwitchVectors, dispmodeId, -1 );
895 createMenu( separator(), viewId, -1 );
896 createMenu( GEOMOp::OpShowAll, viewId, -1 );
897 createMenu( GEOMOp::OpHideAll, viewId, -1 );
898 createMenu( separator(), viewId, -1 );
902 because of these items are accessible through object browser and viewers
903 we have removed they from main menu
905 createMenu( GEOMOp::OpShow, viewId, -1 );
906 createMenu( GEOMOp::OpShowOnly, viewId, -1 );
907 createMenu( GEOMOp::OpHide, viewId, -1 );
910 // ---- create toolbars --------------------------
912 int basicTbId = createTool( tr( "TOOL_BASIC" ) );
913 createTool( GEOMOp::OpPoint, basicTbId );
914 createTool( GEOMOp::OpLine, basicTbId );
915 createTool( GEOMOp::OpCircle, basicTbId );
916 createTool( GEOMOp::OpEllipse, basicTbId );
917 createTool( GEOMOp::OpArc, basicTbId );
918 createTool( GEOMOp::OpCurve, basicTbId );
919 createTool( GEOMOp::OpVector, basicTbId );
920 createTool( GEOMOp::OpPlane, basicTbId );
921 createTool( GEOMOp::OpLCS, basicTbId );
923 int primTbId = createTool( tr( "TOOL_PRIMITIVES" ) );
924 createTool( GEOMOp::OpBox, primTbId );
925 createTool( GEOMOp::OpCylinder, primTbId );
926 createTool( GEOMOp::OpSphere, primTbId );
927 createTool( GEOMOp::OpTorus, primTbId );
928 createTool( GEOMOp::OpCone, primTbId );
929 createTool( GEOMOp::OpRectangle, primTbId );
930 createTool( GEOMOp::OpDisk, primTbId );
932 int boolTbId = createTool( tr( "TOOL_BOOLEAN" ) );
933 createTool( GEOMOp::OpFuse, boolTbId );
934 createTool( GEOMOp::OpCommon, boolTbId );
935 createTool( GEOMOp::OpCut, boolTbId );
936 createTool( GEOMOp::OpSection, boolTbId );
938 int genTbId = createTool( tr( "TOOL_GENERATION" ) );
939 createTool( GEOMOp::OpPrism, genTbId );
940 createTool( GEOMOp::OpRevolution, genTbId );
941 createTool( GEOMOp::OpFilling, genTbId );
942 createTool( GEOMOp::OpPipe, genTbId );
944 int transTbId = createTool( tr( "TOOL_TRANSFORMATION" ) );
945 createTool( GEOMOp::OpTranslate, transTbId );
946 createTool( GEOMOp::OpRotate, transTbId );
947 createTool( GEOMOp::OpChangeLoc, transTbId );
948 createTool( GEOMOp::OpMirror, transTbId );
949 createTool( GEOMOp::OpScale, transTbId );
950 createTool( GEOMOp::OpOffset, transTbId );
951 createTool( separator(), transTbId );
952 createTool( GEOMOp::OpMultiTranslate, transTbId );
953 createTool( GEOMOp::OpMultiRotate, transTbId );
955 int operTbId = createTool( tr( "TOOL_OPERATIONS" ) );
956 createTool( GEOMOp::Op2dSketcher, operTbId );
957 createTool( GEOMOp::Op3dSketcher, operTbId );
958 createTool( separator(), operTbId );
959 createTool( GEOMOp::OpExplode, operTbId );
960 createTool( separator(), operTbId );
961 createTool( GEOMOp::OpPartition, operTbId );
962 createTool( GEOMOp::OpArchimede, operTbId );
963 createTool( GEOMOp::OpShapesOnShape, operTbId );
964 createTool( separator(), operTbId );
965 createTool( GEOMOp::OpFillet1d, operTbId );
966 createTool( GEOMOp::OpFillet2d, operTbId );
967 createTool( GEOMOp::OpFillet3d, operTbId );
968 createTool( GEOMOp::OpChamfer, operTbId );
970 int buildTbId = createTool( tr( "TOOL_BUILD" ) );
971 createTool( GEOMOp::OpEdge, buildTbId );
972 createTool( GEOMOp::OpWire, buildTbId );
973 createTool( GEOMOp::OpFace, buildTbId );
974 createTool( GEOMOp::OpShell, buildTbId );
975 createTool( GEOMOp::OpSolid, buildTbId );
976 createTool( GEOMOp::OpCompound, buildTbId );
978 int advancedTbId = createTool( tr( "TOOL_ADVANCED" ) );
979 //@@ insert new functions before this line @@//
981 // ---- create popup menus --------------------------
983 QString clientOCCorVTK = "(client='OCCViewer' or client='VTKViewer')";
984 QString clientOCCorVTK_AndSomeVisible = clientOCCorVTK + " and selcount>0 and isVisible";
986 QString clientOCCorVTKorOB = "(client='ObjectBrowser' or client='OCCViewer' or client='VTKViewer')";
987 QString clientOCCorVTKorOB_AndSomeVisible = clientOCCorVTKorOB + " and selcount>0 and isVisible";
989 QString autoColorPrefix =
990 "(client='ObjectBrowser' or client='OCCViewer') and type='Shape' and selcount=1 and isOCC=true";
992 QtxPopupMgr* mgr = popupMgr();
993 mgr->insert( action( GEOMOp::OpRename ), -1, -1 ); // rename
994 mgr->setRule( action( GEOMOp::OpRename ), QString("$type in {'Shape' 'Group'} and selcount=1"), QtxPopupMgr::VisibleRule );
995 mgr->insert( action( GEOMOp::OpDelete ), -1, -1 ); // delete
996 mgr->setRule( action( GEOMOp::OpDelete ), QString("$type in {'Shape' 'Group'} and selcount>0"), QtxPopupMgr::VisibleRule );
997 mgr->insert( action( GEOMOp::OpGroupCreatePopup ), -1, -1 ); // create group
998 mgr->setRule( action( GEOMOp::OpGroupCreatePopup ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and isOCC=true"), QtxPopupMgr::VisibleRule );
999 mgr->insert( action( GEOMOp::OpShowChildren ), -1, -1 ); // show children
1000 mgr->setRule( action( GEOMOp::OpShowChildren ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and hasHiddenChildren=true"), QtxPopupMgr::VisibleRule );
1001 mgr->insert( action( GEOMOp::OpHideChildren ), -1, -1 ); // hide children
1002 mgr->setRule( action( GEOMOp::OpHideChildren ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and hasShownChildren=true"), QtxPopupMgr::VisibleRule );
1003 mgr->insert( action( GEOMOp::OpGroupEdit ), -1, -1 ); // edit group
1004 mgr->setRule( action( GEOMOp::OpGroupEdit ), QString("client='ObjectBrowser' and type='Group' and selcount=1 and isOCC=true"), QtxPopupMgr::VisibleRule );
1005 mgr->insert( separator(), -1, -1 ); // -----------
1006 dispmodeId = mgr->insert( tr( "MEN_DISPLAY_MODE" ), -1, -1 ); // display mode menu
1007 mgr->insert( action( GEOMOp::OpWireframe ), dispmodeId, -1 ); // wireframe
1008 mgr->setRule( action( GEOMOp::OpWireframe ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1009 mgr->setRule( action( GEOMOp::OpWireframe ), clientOCCorVTK + " and displaymode='Wireframe'", QtxPopupMgr::ToggleRule );
1010 mgr->insert( action( GEOMOp::OpShading ), dispmodeId, -1 ); // shading
1011 mgr->setRule( action( GEOMOp::OpShading ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1012 mgr->setRule( action( GEOMOp::OpShading ), clientOCCorVTK + " and displaymode='Shading'", QtxPopupMgr::ToggleRule );
1013 mgr->insert( separator(), dispmodeId, -1 );
1014 mgr->insert( action( GEOMOp::OpVectors ), dispmodeId, -1 ); // vectors
1015 mgr->setRule( action( GEOMOp::OpVectors ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1016 mgr->setRule( action( GEOMOp::OpVectors ), clientOCCorVTK + " and isVectorsMode", QtxPopupMgr::ToggleRule );
1017 mgr->insert( separator(), -1, -1 ); // -----------
1018 mgr->insert( action( GEOMOp::OpColor ), -1, -1 ); // color
1019 mgr->setRule( action( GEOMOp::OpColor ), clientOCCorVTKorOB_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1020 mgr->insert( action( GEOMOp::OpTransparency ), -1, -1 ); // transparency
1021 mgr->setRule( action( GEOMOp::OpTransparency ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1022 mgr->insert( action( GEOMOp::OpIsos ), -1, -1 ); // isos
1023 mgr->setRule( action( GEOMOp::OpIsos ), clientOCCorVTK_AndSomeVisible + " and selcount>0 and isVisible", QtxPopupMgr::VisibleRule );
1024 mgr->insert( action( GEOMOp::OpDeflection ), -1, -1 ); // deflection
1025 mgr->setRule( action( GEOMOp::OpDeflection ), clientOCCorVTK_AndSomeVisible + " and selcount>0 and isVisible", QtxPopupMgr::VisibleRule );
1026 mgr->insert( action( GEOMOp::OpPointMarker ), -1, -1 ); // point marker
1027 mgr->setRule( action( GEOMOp::OpPointMarker ), QString( "selcount>0 and $typeid in {%1}" ).arg( GEOM_POINT ), QtxPopupMgr::VisibleRule );
1028 mgr->insert( separator(), -1, -1 ); // -----------
1029 mgr->insert( action( GEOMOp::OpAutoColor ), -1, -1 ); // auto color
1030 mgr->setRule( action( GEOMOp::OpAutoColor ), autoColorPrefix + " and isAutoColor=false", QtxPopupMgr::VisibleRule );
1031 mgr->insert( action( GEOMOp::OpNoAutoColor ), -1, -1 ); // disable auto color
1032 mgr->setRule( action( GEOMOp::OpNoAutoColor ), autoColorPrefix + " and isAutoColor=true", QtxPopupMgr::VisibleRule );
1033 mgr->insert( separator(), -1, -1 ); // -----------
1035 QString canDisplay = "($component={'GEOM'}) and (selcount>0) and ({true} in $canBeDisplayed) ",
1036 onlyComponent = "((type='Component') and selcount=1)",
1037 rule = canDisplay + "and ((($type in {%1}) and( %2 )) or " + onlyComponent + ")",
1038 types = "'Shape' 'Group'";
1040 mgr->insert( action( GEOMOp::OpShow ), -1, -1 ); // display
1041 mgr->setRule( action( GEOMOp::OpShow ), rule.arg( types ).arg( "not isVisible" ), QtxPopupMgr::VisibleRule );
1043 mgr->insert( action( GEOMOp::OpHide ), -1, -1 ); // erase
1044 mgr->setRule( action( GEOMOp::OpHide ), rule.arg( types ).arg( "isVisible" ), QtxPopupMgr::VisibleRule );
1046 mgr->insert( action( GEOMOp::OpHideAll ), -1, -1 ); // erase All
1047 mgr->setRule( action( GEOMOp::OpHideAll ), clientOCCorVTK, QtxPopupMgr::VisibleRule );
1049 QString selectOnly = "(client='OCCViewer' or client='VTKViewer') and (selcount=0)";
1051 int selectolnyId = mgr->insert( tr("MEN_SELECT_ONLY"), -1, -1); //select only menu
1052 mgr->insert( action(GEOMOp::OpSelectVertex), selectolnyId, -1); //Vertex
1053 mgr->setRule(action(GEOMOp::OpSelectVertex), selectOnly, QtxPopupMgr::VisibleRule);
1054 mgr->setRule(action(GEOMOp::OpSelectVertex), selectOnly + " and selectionmode='VERTEX'", QtxPopupMgr::ToggleRule);
1055 mgr->insert( action(GEOMOp::OpSelectEdge), selectolnyId, -1); //Edge
1056 mgr->setRule(action(GEOMOp::OpSelectEdge), selectOnly, QtxPopupMgr::VisibleRule);
1057 mgr->setRule(action(GEOMOp::OpSelectEdge), selectOnly + " and selectionmode='EDGE'", QtxPopupMgr::ToggleRule);
1058 mgr->insert( action(GEOMOp::OpSelectWire), selectolnyId, -1); //Wire
1059 mgr->setRule(action(GEOMOp::OpSelectWire), selectOnly, QtxPopupMgr::VisibleRule);
1060 mgr->setRule(action(GEOMOp::OpSelectWire), selectOnly + " and selectionmode='WIRE'", QtxPopupMgr::ToggleRule);
1061 mgr->insert( action(GEOMOp::OpSelectFace), selectolnyId, -1); //Face
1062 mgr->setRule(action(GEOMOp::OpSelectFace), selectOnly, QtxPopupMgr::VisibleRule);
1063 mgr->setRule(action(GEOMOp::OpSelectFace), selectOnly + " and selectionmode='FACE'", QtxPopupMgr::ToggleRule);
1064 mgr->insert( action(GEOMOp::OpSelectShell), selectolnyId, -1); //Shell
1065 mgr->setRule(action(GEOMOp::OpSelectShell), selectOnly, QtxPopupMgr::VisibleRule);
1066 mgr->setRule(action(GEOMOp::OpSelectShell), selectOnly + " and selectionmode='SHELL'", QtxPopupMgr::ToggleRule);
1067 mgr->insert( action(GEOMOp::OpSelectSolid), selectolnyId, -1); //Solid
1068 mgr->setRule(action(GEOMOp::OpSelectSolid), selectOnly, QtxPopupMgr::VisibleRule);
1069 mgr->setRule(action(GEOMOp::OpSelectSolid), selectOnly + " and selectionmode='SOLID'", QtxPopupMgr::ToggleRule);
1070 mgr->insert( action(GEOMOp::OpSelectCompound), selectolnyId, -1); //Compound
1071 mgr->setRule(action(GEOMOp::OpSelectCompound), selectOnly, QtxPopupMgr::VisibleRule);
1072 mgr->setRule(action(GEOMOp::OpSelectCompound), selectOnly + " and selectionmode='COMPOUND'", QtxPopupMgr::ToggleRule);
1073 mgr->insert( separator(), selectolnyId, -1);
1074 mgr->insert( action(GEOMOp::OpSelectAll), selectolnyId, -1); //Clear selection filter
1075 mgr->setRule(action(GEOMOp::OpSelectAll), selectOnly, QtxPopupMgr::VisibleRule);
1076 mgr->setRule(action(GEOMOp::OpSelectAll), selectOnly + " and selectionmode='ALL'", QtxPopupMgr::ToggleRule);
1077 mgr->insert( action(GEOMOp::OpShowOnly ), -1, -1 ); // display only
1078 mgr->setRule(action(GEOMOp::OpShowOnly ), rule.arg( types ).arg( "true" ), QtxPopupMgr::VisibleRule );
1079 mgr->insert( separator(), -1, -1 );
1081 mgr->hide( mgr->actionId( action( myEraseAll ) ) );
1084 //=======================================================================
1085 // function : GeometryGUI::activateModule()
1086 // purpose : Called when GEOM module is activated
1087 //=======================================================================
1088 bool GeometryGUI::activateModule( SUIT_Study* study )
1090 if ( CORBA::is_nil( myComponentGeom ) )
1093 bool res = SalomeApp_Module::activateModule( study );
1098 setMenuShown( true );
1099 setToolShown( true );
1101 connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1102 this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1104 // Reset actions accelerator keys
1105 action(GEOMOp::OpImport)->setEnabled( true ); // Import: CTRL + Key_I
1106 action(GEOMOp::OpExport)->setEnabled( true ); // Export: CTRL + Key_E
1107 action(GEOMOp::OpDelete)->setEnabled( true ); // Delete: Key_Delete
1108 action(GEOMOp::OpRename)->setEnabled( true ); // Rename: Key_F2
1110 GUIMap::Iterator it;
1111 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1112 it.value()->activate( application()->desktop() );
1114 LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1116 SUIT_ViewManager* vm;
1117 ViewManagerList OCCViewManagers, VTKViewManagers;
1119 application()->viewManagers( OCCViewer_Viewer::Type(), OCCViewManagers );
1120 QListIterator<SUIT_ViewManager*> itOCC( OCCViewManagers );
1121 while ( itOCC.hasNext() && (vm = itOCC.next()) )
1122 myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1124 application()->viewManagers( SVTK_Viewer::Type(), VTKViewManagers );
1125 QListIterator<SUIT_ViewManager*> itVTK( VTKViewManagers );
1126 while ( itVTK.hasNext() && (vm = itVTK.next()) )
1127 myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
1130 SALOME_ListIO selected;
1131 sm->selectedObjects( selected );
1132 sm->clearSelected();
1134 // disable OCC selectors
1135 getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1136 QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1137 while ( itOCCSel.hasNext() )
1138 if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1139 sr->setEnabled(true);
1141 // disable VTK selectors
1142 getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
1143 QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1144 while ( itVTKSel.hasNext() )
1145 if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1146 sr->setEnabled(true);
1148 sm->setSelectedObjects( selected, true ); //NPAL 19674
1150 QMenu* viewMenu = menuMgr()->findMenu( STD_Application::MenuViewId );
1152 connect( viewMenu, SIGNAL( aboutToShow() ), this, SLOT( onViewAboutToShow() ) );
1158 //=======================================================================
1159 // function : GeometryGUI::deactivateModule()
1160 // purpose : Called when GEOM module is deactivated
1161 //=======================================================================
1162 bool GeometryGUI::deactivateModule( SUIT_Study* study )
1164 QMenu* viewMenu = menuMgr()->findMenu( STD_Application::MenuViewId );
1166 disconnect( viewMenu, SIGNAL( aboutToShow() ), this, SLOT( onViewAboutToShow() ) );
1168 setMenuShown( false );
1169 setToolShown( false );
1171 disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1172 this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1174 EmitSignalCloseAllDialogs();
1176 GUIMap::Iterator it;
1177 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1178 it.value()->deactivate();
1180 // Unset actions accelerator keys
1181 action(GEOMOp::OpImport)->setEnabled( false ); // Import: CTRL + Key_I
1182 action(GEOMOp::OpExport)->setEnabled( false ); // Export: CTRL + Key_E
1183 action(GEOMOp::OpDelete)->setEnabled( false ); // Delete: Key_Delete
1184 action(GEOMOp::OpRename)->setEnabled( false ); // Rename: Key_F2
1186 qDeleteAll(myOCCSelectors);
1187 myOCCSelectors.clear();
1188 getApp()->selectionMgr()->setEnabled( true, OCCViewer_Viewer::Type() );
1190 qDeleteAll(myVTKSelectors);
1191 myVTKSelectors.clear();
1192 getApp()->selectionMgr()->setEnabled( true, SVTK_Viewer::Type() );
1194 return SalomeApp_Module::deactivateModule( study );
1197 //=======================================================================
1198 // function : onWindowActivated()
1199 // purpose : update menu items' status - disable non-OCC-viewer-compatible actions
1200 //=======================================================================
1201 void GeometryGUI::onWindowActivated( SUIT_ViewWindow* win )
1206 const bool ViewOCC = ( win->getViewManager()->getType() == OCCViewer_Viewer::Type() );
1207 //const bool ViewVTK = ( win->getViewManager()->getType() == SVTK_Viewer::Type() );
1209 // disable non-OCC viewframe menu commands
1210 // action( GEOMOp::Op2dSketcher )->setEnabled( ViewOCC ); // SKETCHER
1211 action( GEOMOp::OpSuppressFaces )->setEnabled( ViewOCC ); // SuppressFace
1212 action( GEOMOp::OpSuppressHoles )->setEnabled( ViewOCC ); // SuppressHole
1213 action( GEOMOp::OpCloseContour )->setEnabled( ViewOCC ); // CloseContour
1214 action( GEOMOp::OpRemoveIntWires )->setEnabled( ViewOCC ); // RemoveInternalWires
1215 action( GEOMOp::OpAddPointOnEdge )->setEnabled( ViewOCC ); // AddPointOnEdge
1216 // action( GEOMOp::OpFreeBoundaries )->setEnabled( ViewOCC ); // Free boundaries
1218 action( GEOMOp::OpGroupCreate )->setEnabled( ViewOCC ); // Create Group
1219 action( GEOMOp::OpGroupEdit )->setEnabled( ViewOCC ); // Edit Group
1221 action( GEOMOp::OpMultiTransform )->setEnabled( ViewOCC ); // MENU BLOCKS - MULTI-TRANSFORMATION
1224 void GeometryGUI::windows( QMap<int, int>& mappa ) const
1226 mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
1227 mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
1230 void GeometryGUI::viewManagers( QStringList& lst ) const
1232 lst.append( OCCViewer_Viewer::Type() );
1235 void GeometryGUI::onViewManagerAdded( SUIT_ViewManager* vm )
1237 if ( vm->getType() == OCCViewer_Viewer::Type() )
1239 qDebug( "connect" );
1240 connect( vm, SIGNAL( keyPress ( SUIT_ViewWindow*, QKeyEvent* ) ),
1241 this, SLOT( OnKeyPress( SUIT_ViewWindow*, QKeyEvent* ) ) );
1242 connect( vm, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
1243 this, SLOT( OnMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
1244 connect( vm, SIGNAL( mouseMove ( SUIT_ViewWindow*, QMouseEvent* ) ),
1245 this, SLOT( OnMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1247 LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1248 myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1250 // disable OCC selectors
1251 getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1252 QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1253 while ( itOCCSel.hasNext() )
1254 if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1255 sr->setEnabled(true);
1257 else if ( vm->getType() == SVTK_Viewer::Type() )
1259 LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1260 myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
1262 // disable VTK selectors
1263 getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
1264 QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1265 while ( itVTKSel.hasNext() )
1266 if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1267 sr->setEnabled(true);
1271 void GeometryGUI::onViewManagerRemoved( SUIT_ViewManager* vm )
1273 SUIT_ViewModel* viewer = vm->getViewModel();
1274 if ( vm->getType() == OCCViewer_Viewer::Type() )
1276 QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1277 while ( itOCCSel.hasNext() )
1278 if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1279 if ( sr->viewer() == viewer )
1281 delete myOCCSelectors.takeAt( myOCCSelectors.indexOf( sr ) );
1285 if ( vm->getType() == SVTK_Viewer::Type() )
1287 QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1288 while ( itVTKSel.hasNext() )
1289 if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1290 if ( sr->viewer() == viewer )
1292 delete myVTKSelectors.takeAt( myVTKSelectors.indexOf( sr ) );
1298 QString GeometryGUI::engineIOR() const
1300 if ( !CORBA::is_nil( GetGeomGen() ) )
1301 return QString( getApp()->orb()->object_to_string( GetGeomGen() ) );
1305 Handle(Graphic3d_HArray1OfBytes) GeometryGUI::getTexture( SalomeApp_Study* theStudy, int theId, int& theWidth, int& theHeight )
1307 theWidth = theHeight = 0;
1308 Handle(Graphic3d_HArray1OfBytes) aTexture;
1310 TextureMap aTextureMap = myTextureMap[ theStudy->studyDS()->StudyId() ];
1311 aTexture = aTextureMap[ theId ];
1312 if ( aTexture.IsNull() ) {
1313 GEOM::GEOM_IInsertOperations_var aInsOp = GeometryGUI::GetGeomGen()->GetIInsertOperations( theStudy->studyDS()->StudyId() );
1314 if ( !aInsOp->_is_nil() ) {
1315 CORBA::Long aWidth, aHeight;
1316 SALOMEDS::TMPFile_var aStream = aInsOp->GetTexture( theId, aWidth, aHeight );
1317 if ( aWidth > 0 && aHeight > 0 && aStream->length() > 0 ) {
1319 theHeight = aHeight;
1320 aTexture = new Graphic3d_HArray1OfBytes( 1, aStream->length() );
1321 for ( int i = 0; i < aStream->length(); i++ )
1322 aTexture->SetValue( i+1, (Standard_Byte)aStream[i] );
1323 aTextureMap[ theId ] = aTexture;
1331 LightApp_Selection* GeometryGUI::createSelection() const
1333 return new GEOMGUI_Selection();
1336 void GeometryGUI::contextMenuPopup( const QString& client, QMenu* menu, QString& title )
1338 SalomeApp_Module::contextMenuPopup(client, menu, title);
1341 getApp()->selectionMgr()->selectedObjects(lst);
1342 if (lst.Extent() < 1)
1345 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
1346 _PTR(Study) study = appStudy->studyDS();
1348 bool isImported = true;
1349 SALOME_ListIteratorOfListIO anIt (lst);
1350 for (; anIt.More() && isImported; anIt.Next()) {
1351 Handle(SALOME_InteractiveObject) io = anIt.Value();
1352 _PTR(SObject) aSObj = study->FindObjectID(io->getEntry());
1354 if (lst.Extent() == 1) {
1355 // Set context menu title
1356 if (client == "OCCViewer" || client == "VTKViewer")
1357 title = QString(aSObj->GetName().c_str());
1360 CORBA::Object_var anObj = GeometryGUI::ClientSObjectToObject(aSObj);
1361 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(anObj);
1362 if (CORBA::is_nil(aGeomObj) || aGeomObj->GetType() != GEOM_IMPORT)
1370 menu->addAction(action(GEOMOp::OpReimport)); // Reload imported shape
1374 void GeometryGUI::createPreferences()
1376 int tabId = addPreference( tr( "PREF_TAB_SETTINGS" ) );
1378 int genGroup = addPreference( tr( "PREF_GROUP_GENERAL" ), tabId );
1379 setPreferenceProperty( genGroup, "columns", 2 );
1381 int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), genGroup,
1382 LightApp_Preferences::Selector,
1383 "Geometry", "display_mode" );
1385 addPreference( tr( "PREF_SHADING_COLOR" ), genGroup,
1386 LightApp_Preferences::Color, "Geometry", "shading_color" );
1388 addPreference( tr( "PREF_WIREFRAME_COLOR" ), genGroup,
1389 LightApp_Preferences::Color, "Geometry", "wireframe_color" );
1391 addPreference( tr( "PREF_FREE_BOUND_COLOR" ), genGroup,
1392 LightApp_Preferences::Color, "Geometry", "free_bound_color" );
1394 addPreference( tr( "PREF_LINE_COLOR"), genGroup,
1395 LightApp_Preferences::Color, "Geometry", "line_color" );
1397 addPreference( tr( "PREF_POINT_COLOR"), genGroup,
1398 LightApp_Preferences::Color, "Geometry", "point_color" );
1400 addPreference( tr( "PREF_ISOS_COLOR" ), genGroup,
1401 LightApp_Preferences::Color, "Geometry", "isos_color" );
1403 int step = addPreference( tr( "PREF_STEP_VALUE" ), genGroup,
1404 LightApp_Preferences::IntSpin, "Geometry", "SettingsGeomStep" );
1406 int defl = addPreference( tr( "PREF_DEFLECTION" ), genGroup,
1407 LightApp_Preferences::DblSpin, "Geometry", "deflection_coeff" );
1409 int VertexGroup = addPreference( tr( "PREF_GROUP_VERTEX" ), tabId );
1410 setPreferenceProperty( VertexGroup, "columns", 2 );
1412 int typeOfMarker = addPreference( tr( "PREF_TYPE_OF_MARKER" ), VertexGroup,
1413 LightApp_Preferences::Selector, "Geometry", "type_of_marker" );
1415 int markerScale = addPreference( tr( "PREF_MARKER_SCALE" ), VertexGroup,
1416 LightApp_Preferences::Selector, "Geometry", "marker_scale" );
1418 // Set property for default display mode
1419 QStringList aModesList;
1420 aModesList.append( tr("MEN_WIREFRAME") );
1421 aModesList.append( tr("MEN_SHADING") );
1423 QList<QVariant> anIndexesList;
1424 anIndexesList.append(0);
1425 anIndexesList.append(1);
1427 setPreferenceProperty( dispmode, "strings", aModesList );
1428 setPreferenceProperty( dispmode, "indexes", anIndexesList );
1430 // Set property for step value for spinboxes
1431 setPreferenceProperty( step, "min", 1 );
1432 setPreferenceProperty( step, "max", 10000 );
1433 setPreferenceProperty( step, "precision", 3 );
1435 // Set property for deflection value for spinboxes
1436 setPreferenceProperty( defl, "min", DEFLECTION_MIN );
1437 setPreferenceProperty( defl, "max", 1.0 );
1438 setPreferenceProperty( defl, "step", 1.0e-04 );
1439 setPreferenceProperty( defl, "precision", 6 );
1441 // Set property vertex marker type
1442 QList<QVariant> aMarkerTypeIndicesList;
1443 QList<QVariant> aMarkerTypeIconsList;
1445 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1446 for ( int i = GEOM::MT_POINT; i < GEOM::MT_USER; i++ ) {
1447 QString icoFile = QString( "ICON_VERTEX_MARKER_%1" ).arg( i );
1448 QPixmap pixmap = resMgr->loadPixmap( "GEOM", tr( qPrintable( icoFile ) ) );
1449 aMarkerTypeIndicesList << (i-1);
1450 aMarkerTypeIconsList << pixmap;
1453 setPreferenceProperty( typeOfMarker, "indexes", aMarkerTypeIndicesList );
1454 setPreferenceProperty( typeOfMarker, "icons", aMarkerTypeIconsList );
1456 // Set property for vertex marker scale
1457 QList<QVariant> aMarkerScaleIndicesList;
1458 QStringList aMarkerScaleValuesList;
1460 for ( int i = GEOM::MS_10; i <= GEOM::MS_70; i++ ) {
1461 aMarkerScaleIndicesList << i;
1462 aMarkerScaleValuesList << QString::number( (i-(int)GEOM::MS_10)*0.5 + 1.0 );
1465 setPreferenceProperty( markerScale, "strings", aMarkerScaleValuesList );
1466 setPreferenceProperty( markerScale, "indexes", aMarkerScaleIndicesList );
1469 void GeometryGUI::preferencesChanged( const QString& section, const QString& param )
1471 if (section == "Geometry") {
1472 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
1473 if (param == QString("SettingsGeomStep")) {
1474 double spin_step = aResourceMgr->doubleValue(section, param, 100.);
1475 EmitSignalDefaultStepValueChanged(spin_step);
1480 LightApp_Displayer* GeometryGUI::displayer()
1483 myDisplayer = new GEOM_Displayer( dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) );
1487 void GeometryGUI::setLocalSelectionMode(const int mode)
1489 myLocalSelectionMode = mode;
1491 int GeometryGUI::getLocalSelectionMode() const
1493 return myLocalSelectionMode;
1496 const char gSeparator = '_'; // character used to separate parameter names
1497 const char gDigitsSep = ':'; // character used to separate numeric parameter values (color = r:g:b)
1500 * \brief Store visual parameters
1502 * This method is called just before the study document is saved.
1503 * Store visual parameters in AttributeParameter attribue(s)
1505 void GeometryGUI::storeVisualParameters (int savePoint)
1507 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
1508 if (!appStudy || !appStudy->studyDS())
1510 _PTR(Study) studyDS = appStudy->studyDS();
1512 // componentName is used for encoding of entries when storing them in IParameters
1513 std::string componentName = myComponentGeom->ComponentDataType();
1514 //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
1515 //if (!aSComponent) return;
1518 _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
1519 componentName.c_str(),
1521 _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
1523 // viewers counters are used for storing view_numbers in IParameters
1524 int vtkViewers(0), occViewers(0);
1526 QList<SUIT_ViewManager*> lst;
1527 QList<SUIT_ViewManager*>::Iterator it;
1529 // main cycle to store parameters of displayed objects
1531 vtkViewers = occViewers = 0;
1532 getApp()->viewManagers(lst);
1533 for (it = lst.begin(); it != lst.end(); it++)
1535 SUIT_ViewManager* vman = *it;
1536 QString vType = vman->getType();
1538 // saving VTK actors properties
1539 if (vType == SVTK_Viewer::Type())
1541 QVector<SUIT_ViewWindow*> views = vman->getViews();
1542 for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++)
1544 if (SVTK_ViewWindow* vtkView = dynamic_cast<SVTK_ViewWindow*>(views[i]))
1546 vtkActorCollection* allActors = vtkView->getRenderer()->GetActors();
1547 allActors->InitTraversal();
1548 while (vtkActor* actor = allActors->GetNextActor())
1550 if (actor->GetVisibility()) // store only visible actors
1552 GEOM_Actor* aGeomActor = 0;
1553 if (actor->IsA("GEOM_Actor"))
1554 aGeomActor = GEOM_Actor::SafeDownCast(actor);
1555 if (aGeomActor && aGeomActor->hasIO())
1557 Handle(SALOME_InteractiveObject) io = aGeomActor->getIO();
1560 // entry is "encoded" = it does NOT contain component adress, since it is a
1561 // subject to change on next component loading
1562 std::string entry = ip->encodeEntry(io->getEntry(), componentName);
1564 std::string param, occParam = vType.toLatin1().data();
1565 occParam += gSeparator;
1566 occParam += QString::number(vtkViewers).toLatin1().data();
1567 occParam += gSeparator;
1569 param = occParam + "Visibility";
1570 ip->setParameter(entry, param, "On");
1572 param = occParam + "DisplayMode";
1573 ip->setParameter(entry, param, QString::number
1574 (aGeomActor->getDisplayMode()).toLatin1().data());
1576 vtkFloatingPointType r, g, b;
1577 aGeomActor->GetColor(r, g, b);
1578 QString colorStr = QString::number(r);
1579 colorStr += gDigitsSep; colorStr += QString::number(g);
1580 colorStr += gDigitsSep; colorStr += QString::number(b);
1581 param = occParam + "Color";
1582 ip->setParameter(entry, param, colorStr.toLatin1().data());
1584 param = occParam + "Opacity";
1585 ip->setParameter(entry, param, QString::number(aGeomActor->GetOpacity()).toLatin1().data());
1587 int nbUIso(0), nbVIso(0);
1588 aGeomActor->GetNbIsos(nbUIso,nbVIso);
1589 QString isosStr = QString::number(nbUIso);
1590 isosStr += gDigitsSep;
1591 isosStr += QString::number(nbVIso);
1592 param = occParam + "Isos";
1593 ip->setParameter(entry, param, isosStr.toLatin1().data());
1594 } // if (io->hasEntry())
1595 } // GEOM_Actor && hasIO
1597 } // while.. actors traversal
1601 } // if (SVTK view model)
1602 else if (vType == SOCC_Viewer::Type()) // processing OCC viewers
1604 QVector<SUIT_ViewWindow*> views = vman->getViews();
1605 for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++)
1607 SOCC_ViewWindow* occView = dynamic_cast<SOCC_ViewWindow*>(views[i]);
1610 //Handle(AIS_InteractiveContext) ic =
1611 // ((OCCViewer_Viewer*)(occView->getViewManager()->getViewModel()))->getAISContext();
1612 OCCViewer_Viewer* viewModel = (OCCViewer_Viewer*)(vman->getViewModel());
1613 //OCCViewer_Viewer* viewModel = ((OCCViewer_ViewManager*)vman)->getOCCViewer();
1614 Handle(AIS_InteractiveContext) ic = viewModel->getAISContext();
1616 AIS_ListOfInteractive aList;
1617 ic->DisplayedObjects(aList);
1619 AIS_ListIteratorOfListOfInteractive ite (aList);
1620 for (; ite.More(); ite.Next())
1622 if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape)))
1624 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
1627 Handle(SALOME_InteractiveObject) io =
1628 Handle(SALOME_InteractiveObject)::DownCast(aSh->getIO());
1631 // entry is "encoded": it does NOT contain component adress,
1632 // since it is a subject to change on next component loading
1633 std::string entry = ip->encodeEntry(io->getEntry(), componentName);
1635 std::string param, occParam = vType.toLatin1().data();
1636 occParam += gSeparator;
1637 occParam += QString::number(occViewers).toLatin1().data();
1638 occParam += gSeparator;
1641 param = occParam + "Visibility";
1642 ip->setParameter(entry, param, "On");
1645 param = occParam + "DisplayMode";
1646 int dm = aSh->DisplayMode();
1647 ip->setParameter(entry, param, QString::number(dm).toLatin1().data());
1650 // is a property of GEOM_Object, it is stored by GEOM engine
1653 param = occParam + "Transparency";
1654 ip->setParameter(entry, param, QString::number(aSh->Transparency()).toLatin1().data());
1657 Handle(AIS_Drawer) aDrawer = aSh->Attributes();
1658 int nbUIso = aDrawer->UIsoAspect()->Number();
1659 int nbVIso = aDrawer->VIsoAspect()->Number();
1660 QString isosStr = QString::number(nbUIso);
1661 isosStr += gDigitsSep;
1662 isosStr += QString::number(nbVIso);
1663 param = occParam + "Isos";
1664 ip->setParameter(entry, param, isosStr.toLatin1().data());
1665 } // if (io->hasEntry())
1667 } // if (GEOM_AISShape)
1668 } // for (AIS_ListOfInteractive)
1672 } // if (SOCC view model)
1675 // unknown viewer type
1677 } // for (viewManagers)
1681 * \brief Restore visual parameters
1683 * This method is called after the study document is opened.
1684 * Restore visual parameters from AttributeParameter attribue(s)
1686 void GeometryGUI::restoreVisualParameters (int savePoint)
1688 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
1689 if (!appStudy || !appStudy->studyDS())
1691 _PTR(Study) studyDS = appStudy->studyDS();
1693 // componentName is used for encoding of entries when storing them in IParameters
1694 std::string componentName = myComponentGeom->ComponentDataType();
1695 //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
1696 //if (!aSComponent) return;
1699 _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
1700 componentName.c_str(),
1702 _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
1704 std::vector<std::string> entries = ip->getEntries();
1706 for (std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt)
1708 // entry is a normal entry - it should be "decoded" (setting base adress of component)
1709 QString entry (ip->decodeEntry(*entIt).c_str());
1711 // Check that the entry corresponds to a real object in the Study
1712 // as the object may be deleted or modified after the visual state is saved.
1713 _PTR(SObject) so = studyDS->FindObjectID(entry.toLatin1().data());
1714 if (!so) continue; //Skip the not existent entry
1716 std::vector<std::string> paramNames = ip->getAllParameterNames( *entIt );
1717 std::vector<std::string> paramValues = ip->getAllParameterValues( *entIt );
1719 std::vector<std::string>::iterator namesIt = paramNames.begin();
1720 std::vector<std::string>::iterator valuesIt = paramValues.begin();
1722 // actors are stored in a map after displaying of them for
1723 // quicker access in the future: map < viewID to actor >
1724 NCollection_DataMap<int, GEOM_Actor* > vtkActors;
1725 NCollection_DataMap<int, Handle(GEOM_AISShape)> occActors;
1727 for (; namesIt != paramNames.end(); ++namesIt, ++valuesIt)
1729 // visual parameters are stored in strings as follows: ViewerType_ViewIndex_ParamName.
1730 // '_' is used as separator and should not be used in viewer type or parameter names.
1731 QStringList lst = QString((*namesIt).c_str()).split(gSeparator, QString::SkipEmptyParts);
1732 if (lst.size() != 3)
1735 QString viewerTypStr = lst[0];
1736 QString viewIndexStr = lst[1];
1737 QString paramNameStr = lst[2];
1740 int viewIndex = viewIndexStr.toUInt(&ok);
1741 if (!ok) // bad conversion of view index to integer
1745 if (viewerTypStr == SVTK_Viewer::Type())
1747 GEOM_Actor* vActor = 0;
1748 if (vtkActors.IsBound(viewIndex))
1749 vActor = vtkActors.Find(viewIndex);
1751 if (paramNameStr == "Visibility")
1753 if (!vActor && displayer())
1755 QList<SUIT_ViewManager*> lst;
1756 getApp()->viewManagers(viewerTypStr, lst);
1758 // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
1759 if (viewIndex >= 0 && viewIndex < lst.count()) {
1760 SUIT_ViewManager* vman = lst.at(viewIndex);
1761 SUIT_ViewModel* vmodel = vman->getViewModel();
1762 // SVTK view model can be casted to SALOME_View
1763 displayer()->Display(entry, true, dynamic_cast<SALOME_View*>(vmodel));
1765 // store displayed actor in a temporary map for quicker
1766 // access later when restoring other parameters
1767 SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
1768 vtkRenderer* Renderer = vtkView->getRenderer();
1769 vtkActorCollection* theActors = Renderer->GetActors();
1770 theActors->InitTraversal();
1771 bool isFound = false;
1772 vtkActor *ac = theActors->GetNextActor();
1773 for (; ac != NULL && !isFound; ac = theActors->GetNextActor()) {
1774 if (ac->IsA("GEOM_Actor")) {
1775 GEOM_Actor* aGeomAc = GEOM_Actor::SafeDownCast(ac);
1776 if (aGeomAc->hasIO()) {
1777 Handle(SALOME_InteractiveObject) io =
1778 Handle(SALOME_InteractiveObject)::DownCast(aGeomAc->getIO());
1779 if (io->hasEntry() && strcmp(io->getEntry(), entry.toLatin1().data()) == 0) {
1781 vtkActors.Bind(viewIndex, aGeomAc);
1788 } // if (paramNameStr == "Visibility")
1791 // the rest properties "work" with GEOM_Actor
1794 QString val ((*valuesIt).c_str());
1796 if (paramNameStr == "DisplayMode") {
1797 vActor->setDisplayMode(val.toInt());
1799 else if (paramNameStr == "Color") {
1800 QStringList colors = val.split(gDigitsSep, QString::SkipEmptyParts);
1801 if (colors.count() == 3)
1802 vActor->SetColor(colors[0].toFloat(), colors[1].toFloat(), colors[2].toFloat());
1804 else if (paramNameStr == "Opacity") {
1805 vActor->SetOpacity(val.toFloat());
1807 else if (paramNameStr == "Isos") {
1808 QStringList isos = val.split(gDigitsSep, QString::SkipEmptyParts);
1809 if (isos.count() == 2) {
1810 int aIsos[2] = {isos[0].toInt(), isos[1].toInt()};
1811 vActor->SetNbIsos(aIsos);
1815 } // other parameters than Visibility
1817 else if (viewerTypStr == SOCC_Viewer::Type())
1819 //Handle(AIS_InteractiveObject) occActor;
1820 Handle(GEOM_AISShape) occActor;
1821 if (occActors.IsBound(viewIndex))
1822 occActor = occActors.Find(viewIndex);
1824 // ViewModel and InteractiveContext
1825 SOCC_Viewer* occVModel = 0;
1826 Handle(AIS_InteractiveContext) ic;
1828 QList<SUIT_ViewManager*> lst;
1829 getApp()->viewManagers(viewerTypStr, lst);
1831 // SOCC ViewManager always has 1 ViewWindow, so view index is index of view manager
1832 if (viewIndex >= 0 && viewIndex < lst.count()) {
1833 SUIT_ViewManager* vman = lst.at(viewIndex);
1834 SUIT_ViewModel* vmodel = vman->getViewModel();
1835 occVModel = dynamic_cast<SOCC_Viewer*>(vmodel);
1837 ic = occVModel->getAISContext();
1843 if (paramNameStr == "Visibility")
1845 if (occActor.IsNull() && displayer())
1847 displayer()->Display(entry, true, occVModel);
1849 // store displayed actor in a temporary map for quicker
1850 // access later when restoring other parameters
1851 AIS_ListOfInteractive aList;
1852 ic->DisplayedObjects(aList);
1853 bool isFound = false;
1854 AIS_ListIteratorOfListOfInteractive ite (aList);
1855 for (; ite.More() && !isFound; ite.Next()) {
1856 if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
1857 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
1859 Handle(SALOME_InteractiveObject) io =
1860 Handle(SALOME_InteractiveObject)::DownCast(aSh->getIO());
1861 if (io->hasEntry() && strcmp(io->getEntry(), entry.toLatin1().data()) == 0) {
1863 occActors.Bind(viewIndex, aSh);
1869 } // if (paramNameStr == "Visibility")
1872 // the rest properties "work" with GEOM_AISShape
1873 if (!occActor.IsNull())
1875 QString val ((*valuesIt).c_str());
1877 if (paramNameStr == "DisplayMode") {
1878 ic->SetDisplayMode(occActor, AIS_DisplayMode(val.toInt()), false);
1879 //ic->Redisplay(occActor, Standard_False, Standard_True);
1881 // Color is restored by the GEOM engine
1882 else if (paramNameStr == "Transparency") {
1883 ic->SetTransparency(occActor, val.toFloat(), false);
1884 ic->Redisplay(occActor, Standard_False, Standard_True);
1886 else if (paramNameStr == "Isos") {
1887 QStringList isos = val.split(gDigitsSep, QString::SkipEmptyParts);
1888 if (isos.count() == 2) {
1889 Handle(AIS_Drawer) aDrawer = occActor->Attributes();
1890 int nbUIso = isos[0].toInt();
1891 int nbVIso = isos[1].toInt();
1892 Handle(Prs3d_IsoAspect) uIsoAspect = aDrawer->UIsoAspect();
1893 Handle(Prs3d_IsoAspect) vIsoAspect = aDrawer->VIsoAspect();
1894 uIsoAspect->SetNumber(nbUIso);
1895 vIsoAspect->SetNumber(nbVIso);
1896 aDrawer->SetUIsoAspect(uIsoAspect);
1897 aDrawer->SetVIsoAspect(vIsoAspect);
1898 ic->SetLocalAttributes(occActor, aDrawer);
1899 ic->Redisplay(occActor);
1903 } // other parameters than Visibility
1907 // unknown viewer type
1909 } // for names/parameters iterator
1910 } // for entries iterator
1912 // update all VTK and OCC views
1913 QList<SUIT_ViewManager*> lst;
1914 getApp()->viewManagers(lst);
1915 for (QList<SUIT_ViewManager*>::Iterator it = lst.begin(); it != lst.end(); it++) {
1916 SUIT_ViewModel* vmodel = (*it)->getViewModel();
1919 if (vmodel->getType() == SVTK_Viewer::Type()) {
1920 SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) (*it)->getActiveView();
1921 vtkView->getRenderer()->ResetCameraClippingRange();
1924 else if (vmodel->getType() == SOCC_Viewer::Type()) {
1925 //SOCC_ViewWindow* occView = (SOCC_ViewWindow*) (*it)->getActiveView();
1926 SALOME_View* occVMod = dynamic_cast<SALOME_View*>(vmodel);
1933 void GeometryGUI::onViewAboutToShow()
1935 SUIT_ViewWindow* window = application()->desktop()->activeWindow();
1936 QAction* a = action( GEOMOp::OpSwitchVectors );
1938 a->setEnabled(true);
1939 bool vmode = window->getCustomData("VectorsMode").toBool();
1940 a->setText ( vmode == 1 ? tr( "MEN_VECTOR_MODE_OFF" ) : tr("MEN_VECTOR_MODE_ON") );
1942 a->setText ( tr("MEN_VECTOR_MODE_ON") );
1943 a->setEnabled(false);