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 "GEOMGUI_OCCSelector.h"
28 #include "GEOMGUI_Selection.h"
29 #include "GEOM_Displayer.h"
30 #include "GEOM_AISShape.hxx"
32 #include "GEOM_Actor.h"
34 #include <SUIT_Desktop.h>
35 #include <SUIT_MessageBox.h>
36 #include <SUIT_ResourceMgr.h>
37 #include <SUIT_Session.h>
38 #include <SUIT_ViewManager.h>
40 #include <OCCViewer_ViewWindow.h>
41 #include <OCCViewer_ViewPort3d.h>
42 #include <OCCViewer_ViewModel.h>
43 #include <OCCViewer_ViewManager.h>
45 #include <SOCC_ViewModel.h>
46 #include <SOCC_ViewWindow.h>
48 #include <SVTK_ViewWindow.h>
49 #include <SVTK_RenderWindowInteractor.h>
50 #include <SVTK_InteractorStyle.h>
51 #include <SVTK_ViewModel.h>
53 #include <SalomeApp_Application.h>
54 #include <SalomeApp_Study.h>
56 #include <LightApp_SelectionMgr.h>
57 #include <LightApp_VTKSelector.h>
58 #include <LightApp_DataObject.h>
59 #include <LightApp_Preferences.h>
61 #include <SALOME_LifeCycleCORBA.hxx>
62 #include <SALOME_ListIO.hxx>
63 #include <SALOME_ListIteratorOfListIO.hxx>
65 #include <SALOMEDSClient_ClientFactory.hxx>
66 #include <SALOMEDSClient_IParameters.hxx>
75 #include <AIS_Drawer.hxx>
76 #include <AIS_ListOfInteractive.hxx>
77 #include <AIS_ListIteratorOfListOfInteractive.hxx>
78 #include <Prs3d_Drawer.hxx>
79 #include <Prs3d_IsoAspect.hxx>
80 #include <Aspect_TypeOfMarker.hxx>
81 #include <OSD_SharedLibrary.hxx>
82 #include <NCollection_DataMap.hxx>
84 #include <utilities.h>
86 #include <vtkCamera.h>
87 #include <vtkRenderer.h>
89 #include "GEOMImpl_Types.hxx"
94 Standard_EXPORT CAM_Module* createModule() {
95 return new GeometryGUI();
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 : JoinObjectParameters
155 //=======================================================================
156 char* GeometryGUI::JoinObjectParameters(const QStringList& theParametersList)
158 return theParametersList.join(":").toLatin1().data();
160 //=======================================================================
161 // function : GeometryGUI::GeometryGUI()
162 // purpose : Constructor
163 //=======================================================================
164 GeometryGUI::GeometryGUI() :
165 SalomeApp_Module( "GEOM" ),
166 LightApp_Module( "GEOM" )
168 if ( CORBA::is_nil( myComponentGeom ) )
170 SALOME_LifeCycleCORBA* ls = new SALOME_LifeCycleCORBA( getApp()->namingService() );
171 Engines::Component_var comp = ls->FindOrLoad_Component( "FactoryServer", "GEOM" );
172 myComponentGeom = GEOM::GEOM_Gen::_narrow( comp );
176 myActiveDialogBox = 0;
179 gp_Pnt origin = gp_Pnt(0., 0., 0.);
180 gp_Dir direction = gp_Dir(0., 0., 1.);
181 myWorkingPlane = gp_Ax3(origin, direction);
184 myLocalSelectionMode = GEOM_ALLOBJECTS;
187 //=======================================================================
188 // function : GeometryGUI::~GeometryGUI()
189 // purpose : Destructor
190 //=======================================================================
191 GeometryGUI::~GeometryGUI()
193 while (!myOCCSelectors.isEmpty())
194 delete myOCCSelectors.takeFirst();
196 while (!myVTKSelectors.isEmpty())
197 delete myVTKSelectors.takeFirst();
200 //=======================================================================
201 // function : GeometryGUI::getLibrary()
202 // purpose : get or load GUI library by name [ internal ]
203 //=======================================================================
204 typedef GEOMGUI* (*LibraryGUI)( GeometryGUI* );
205 GEOMGUI* GeometryGUI::getLibrary( const QString& libraryName )
207 if ( !myGUIMap.contains( libraryName ) ) {
208 // try to load library if it is not loaded yet
211 libs = getenv( "LD_LIBRARY_PATH" );
212 if( !libs.isEmpty() ) {
213 QStringList dirList = libs.split( ":", QString::SkipEmptyParts ); // skip empty entries
215 libs = getenv( "PATH" );
216 if( !libs.isEmpty() ) {
217 QStringList dirList = libs.split( ";", QString::SkipEmptyParts ); // skip empty entries
219 for( int i = dirList.count()-1; i >= 0; i-- ) {
220 QString dir = dirList[ i ];
221 QFileInfo fi( Qtx::addSlash( dirList[ i ] ) + libraryName );
223 OSD_SharedLibrary aSharedLibrary( fi.fileName().toLatin1().data() );
224 bool res = aSharedLibrary.DlOpen( OSD_RTLD_LAZY );
226 MESSAGE( "Can't open library : " << aSharedLibrary.DlError() );
227 continue; // continue search further
229 OSD_Function osdF = aSharedLibrary.DlSymb( "GetLibGUI" );
230 if ( osdF != NULL ) {
231 LibraryGUI func = (GEOMGUI* (*) (GeometryGUI*))osdF;
232 GEOMGUI* libGUI = (*func)(this);
234 myGUIMap[ libraryName ] = libGUI;
235 break; // found and loaded!
242 if ( myGUIMap.contains( libraryName ) )
243 // library is successfully loaded
244 return myGUIMap[ libraryName ];
248 //=======================================================================
249 // function : GeometryGUI::ActiveWorkingPlane()
250 // purpose : Activate Working Plane View
251 //=======================================================================
252 void GeometryGUI::ActiveWorkingPlane()
254 gp_Dir DZ = myWorkingPlane.Direction();
255 gp_Dir DY = myWorkingPlane.YDirection();
257 SUIT_ViewWindow* window = application()->desktop()->activeWindow();
258 bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
259 bool ViewVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
262 OCCViewer_ViewWindow* vw = dynamic_cast<OCCViewer_ViewWindow*>( window );
264 Handle(V3d_View) view3d = vw->getViewPort()->getView();
266 view3d->SetProj(DZ.X(), DZ.Y(), DZ.Z());
267 view3d->SetUp(DY.X(), DY.Y(), DY.Z());
273 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( window );
275 vtkCamera* camera = vw->getRenderer()->GetActiveCamera();
277 camera->SetPosition(DZ.X(), DZ.Y(), DZ.Z());
278 camera->SetViewUp(DY.X(), DY.Y(), DY.Z());
279 camera->SetFocalPoint(0,0,0);
286 //=======================================================================
287 // function : GeometryGUI::SetActiveDialogBox()
288 // purpose : Set active dialog box
289 //=======================================================================
290 void GeometryGUI::SetActiveDialogBox( QDialog* aDlg )
292 myActiveDialogBox = (QDialog*)aDlg;
295 //=======================================================================
296 // function : GeometryGUI::EmitSignalDeactivateDialog()
297 // purpose : Emit a signal to deactivate the active dialog Box
298 //=======================================================================
299 void GeometryGUI::EmitSignalDeactivateDialog()
301 emit SignalDeactivateActiveDialog();
304 //=======================================================================
305 // function : GeometryGUI::EmitSignalCloseAllDialogs()
306 // purpose : Emit a signal to close all non modal dialogs box
307 //=======================================================================
308 void GeometryGUI::EmitSignalCloseAllDialogs()
310 emit SignalCloseAllDialogs();
313 //=======================================================================
314 // function : GeometryGUI::EmitSignalDefaultStepValueChanged()
315 // purpose : Emit a signal to inform that default real spin box step has
317 //=======================================================================
318 void GeometryGUI::EmitSignalDefaultStepValueChanged(double newVal)
320 emit SignalDefaultStepValueChanged(newVal);
323 //=======================================================================
324 // function : GeometryGUI::OnGUIEvent()
325 // purpose : common slot for all menu/toolbar actions
326 //=======================================================================
327 void GeometryGUI::OnGUIEvent()
329 const QObject* obj = sender();
330 if ( !obj || !obj->inherits( "QAction" ) )
332 int id = actionId((QAction*)obj);
337 //=======================================================================
338 // function : GeometryGUI::OnGUIEvent()
339 // purpose : manage all events on GUI [static]
340 //=======================================================================
341 void GeometryGUI::OnGUIEvent( int id )
343 SUIT_Application* anApp = application();
345 SUIT_Desktop* desk = anApp->desktop();
347 // check type of the active viewframe
348 SUIT_ViewWindow* window = desk->activeWindow();
349 bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
350 bool ViewVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
351 // if current viewframe is not of OCC and not of VTK type - return immediately
352 // fix for IPAL8958 - allow some commands to execute even when NO viewer is active (rename for example)
353 bool NotViewerDependentCommand = ( id == 901 || id == 216 || id == 213 );
354 if ( !ViewOCC && !ViewVTK && !NotViewerDependentCommand )
357 // fix for IPAL9103, point 2
358 if ( CORBA::is_nil( GetGeomGen() ) ) {
359 SUIT_MessageBox::critical( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_GET_ENGINE" ), tr( "GEOM_BUT_OK" ) );
363 GEOMGUI* library = 0;
364 // try to get-or-load corresponding GUI library
365 if( id == 111 || // MENU FILE - IMPORT BREP
366 id == 112 || // MENU FILE - IMPORT IGES
367 id == 113 || // MENU FILE - IMPORT STEP
368 id == 121 || // MENU FILE - EXPORT BREP
369 id == 122 || // MENU FILE - EXPORT IGES
370 id == 123 || // MENU FILE - EXPORT STEP
371 id == 2171 || // POPUP VIEWER - SELECT ONLY - VERTEX
372 id == 2172 || // POPUP VIEWER - SELECT ONLY - EDGE
373 id == 2173 || // POPUP VIEWER - SELECT ONLY - WIRE
374 id == 2174 || // POPUP VIEWER - SELECT ONLY - FACE
375 id == 2175 || // POPUP VIEWER - SELECT ONLY - SHELL
376 id == 2176 || // POPUP VIEWER - SELECT ONLY - SOLID
377 id == 2177 || // POPUP VIEWER - SELECT ONLY - COMPOUND
378 id == 2178 || // POPUP VIEWER - SELECT ONLY - SELECT ALL
379 id == 31 || // MENU EDIT - COPY
380 id == 33 || // MENU EDIT - DELETE
381 id == 411 || // MENU SETTINGS - ADD IN STUDY
382 id == 412 || // MENU SETTINGS - SHADING COLOR
383 id == 5103 || // MENU TOOLS - CHECK GEOMETRY
384 id == 8032 || // POPUP VIEWER - COLOR
385 id == 8033 || // POPUP VIEWER - TRANSPARENCY
386 id == 8034 || // POPUP VIEWER - ISOS
387 id == 8035 || // POPUP VIEWER - AUTO COLOR
388 id == 8036 || // POPUP VIEWER - DISABLE AUTO COLOR
389 id == 8037 || // POPUP VIEWER - SHOW CHILDREN
390 id == 8038 || // POPUP VIEWER - HIDE CHILDREN
391 id == 804 || // POPUP VIEWER - ADD IN STUDY
392 id == 901 || // OBJECT BROWSER - RENAME
393 id == 9024 ) { // OBJECT BROWSER - OPEN
394 //cout << "id " << id << " received" << endl;
396 library = getLibrary( "libGEOMToolsGUI.so" );
398 library = getLibrary( "GEOMToolsGUI.dll" );
401 else if( id == 211 || // MENU VIEW - WIREFRAME/SHADING
402 id == 212 || // MENU VIEW - DISPLAY ALL
403 id == 213 || // MENU VIEW - DISPLAY ONLY
404 id == 214 || // MENU VIEW - ERASE ALL
405 id == 215 || // MENU VIEW - ERASE
406 id == 216 || // MENU VIEW - DISPLAY
407 id == 218 || // MENU VIEW - VECTOR MODE
408 id == 80311 || // POPUP VIEWER - WIREFRAME
409 id == 80312 || // POPUP VIEWER - SHADING
410 id == 80313 ) { // POPUP VIEWER - VECTORS
412 library = getLibrary( "libDisplayGUI.so" );
414 library = getLibrary( "DisplayGUI.dll" );
417 else if( id == 4011 || // MENU BASIC - POINT
418 id == 4012 || // MENU BASIC - LINE
419 id == 4013 || // MENU BASIC - CIRCLE
420 id == 4014 || // MENU BASIC - ELLIPSE
421 id == 4015 || // MENU BASIC - ARC
422 id == 4016 || // MENU BASIC - VECTOR
423 id == 4017 || // MENU BASIC - PLANE
424 // id == 4018 || // MENU BASIC - WPLANE // DEPRECATED
425 id == 4019 || // MENU BASIC - CURVE
426 id == 4020 ) { // MENU BASIC - REPAIR
428 library = getLibrary( "libBasicGUI.so" );
430 library = getLibrary( "BasicGUI.dll" );
433 else if( id == 4021 || // MENU PRIMITIVE - BOX
434 id == 4022 || // MENU PRIMITIVE - CYLINDER
435 id == 4023 || // MENU PRIMITIVE - SPHERE
436 id == 4024 || // MENU PRIMITIVE - TORUS
437 id == 4025 || // MENU PRIMITIVE - CONE
438 id == 4026 || // MENU PRIMITIVE - FACE
439 id == 4027 ) { // MENU PRIMITIVE - DISK
441 library = getLibrary( "libPrimitiveGUI.so" );
443 library = getLibrary( "PrimitiveGUI.dll" );
446 else if( id == 4031 || // MENU GENERATION - PRISM
447 id == 4032 || // MENU GENERATION - REVOLUTION
448 id == 4033 || // MENU GENERATION - FILLING
449 id == 4034 ) { // MENU GENERATION - PIPE
451 library = getLibrary( "libGenerationGUI.so" );
453 library = getLibrary( "GenerationGUI.dll" );
456 else if( id == 404 || // MENU ENTITY - SKETCHER
457 id == 405 || // MENU ENTITY - 3D SKETCHER
458 id == 407 ) { // MENU ENTITY - EXPLODE
460 library = getLibrary( "libEntityGUI.so" );
462 library = getLibrary( "EntityGUI.dll" );
465 else if( id == 4081 || // MENU BUILD - EDGE
466 id == 4082 || // MENU BUILD - WIRE
467 id == 4083 || // MENU BUILD - FACE
468 id == 4084 || // MENU BUILD - SHELL
469 id == 4085 || // MENU BUILD - SOLID
470 id == 4086 ) { // MENU BUILD - COMPUND
472 library = getLibrary( "libBuildGUI.so" );
474 library = getLibrary( "BuildGUI.dll" );
477 else if( id == 5011 || // MENU BOOLEAN - FUSE
478 id == 5012 || // MENU BOOLEAN - COMMON
479 id == 5013 || // MENU BOOLEAN - CUT
480 id == 5014 ) { // MENU BOOLEAN - SECTION
482 library = getLibrary( "libBooleanGUI.so" );
484 library = getLibrary( "BooleanGUI.dll" );
487 else if( id == 5021 || // MENU TRANSFORMATION - TRANSLATION
488 id == 5022 || // MENU TRANSFORMATION - ROTATION
489 id == 5023 || // MENU TRANSFORMATION - LOCATION
490 id == 5024 || // MENU TRANSFORMATION - MIRROR
491 id == 5025 || // MENU TRANSFORMATION - SCALE
492 id == 5026 || // MENU TRANSFORMATION - OFFSET
493 id == 5027 || // MENU TRANSFORMATION - MULTI-TRANSLATION
494 id == 5028 || // MENU TRANSFORMATION - MULTI-ROTATION
495 id == 5029 ) { // CONTEXT(POPUP) MENU - RELOAD_IMPORTED
497 library = getLibrary( "libTransformationGUI.so" );
499 library = getLibrary( "TransformationGUI.dll" );
502 else if( id == 503 || // MENU OPERATION - PARTITION
503 id == 504 || // MENU OPERATION - ARCHIMEDE
504 id == 505 || // MENU OPERATION - FILLET
505 id == 506 || // MENU OPERATION - CHAMFER
506 id == 507 || // MENU OPERATION - CLIPPING RANGE
507 id == 508 || // MENU OPERATION - GET SHAPES ON SHAPE
508 id == 509 || // MENU OPERATION - FILLET 2D
509 id == 510 ) { // MENU OPERATION - FILLET 1D
511 library = getLibrary( "libOperationGUI.so" );
513 library = getLibrary( "OperationGUI.dll" );
516 else if( id == 601 || // MENU REPAIR - SEWING
517 id == 603 || // MENU REPAIR - SUPPRESS FACES
518 id == 604 || // MENU REPAIR - SUPPRESS HOLE
519 id == 605 || // MENU REPAIR - SHAPE PROCESSING
520 id == 606 || // MENU REPAIR - CLOSE CONTOUR
521 id == 607 || // MENU REPAIR - REMOVE INTERNAL WIRES
522 id == 608 || // MENU REPAIR - ADD POINT ON EDGE
523 id == 609 || // MENU MEASURE - FREE BOUNDARIES
524 id == 610 || // MENU MEASURE - FREE FACES
525 id == 611 || // MENU REPAIR - CHANGE ORIENTATION
526 id == 602 || // MENU REPAIR - GLUE FACES
527 id == 612 ) { // MENU REPAIR - REMOVE EXTRA EDGES
529 library = getLibrary( "libRepairGUI.so" );
531 library = getLibrary( "RepairGUI.dll" );
534 else if( id == 701 || // MENU MEASURE - PROPERTIES
535 id == 702 || // MENU MEASURE - CDG
536 id == 703 || // MENU MEASURE - INERTIA
537 id == 704 || // MENU MEASURE - NORMALE
538 id == 7041 || // MENU MEASURE - BOUNDING BOX
539 id == 7042 || // MENU MEASURE - MIN DISTANCE
540 id == 7043 || // MENU MEASURE - ANGLE
541 id == 705 || // MENU MEASURE - TOLERANCE
542 id == 706 || // MENU MEASURE - WHATIS
543 id == 707 || // MENU MEASURE - CHECK
544 id == 7072 || // MENU MEASURE - CHECK COMPOUND OF BLOCKS
545 id == 708 ) { // MENU MEASURE - POINT COORDINATES
547 library = getLibrary( "libMeasureGUI.so" );
549 library = getLibrary( "MeasureGUI.dll" );
552 else if( id == 800 || // MENU GROUP - CREATE
553 id == 8001 || // POPUP MENU - CREATE GROUP
554 id == 801 ) { // MENU GROUP - EDIT
556 library = getLibrary( "libGroupGUI.so" );
558 library = getLibrary( "GroupGUI.dll" );
561 else if( id == 9999 || // MENU BLOCKS - HEXAHEDRAL SOLID
562 id == 9998 || // MENU BLOCKS - MULTI-TRANSFORMATION
563 id == 9997 || // MENU BLOCKS - QUADRANGLE FACE
564 id == 99991 || // MENU BLOCKS - PROPAGATE
565 id == 9995 ) { // MENU BLOCKS - EXPLODE ON BLOCKS
567 library = getLibrary( "libBlocksGUI.so" );
569 library = getLibrary( "BlocksGUI.dll" );
573 // call method of corresponding GUI library
575 library->OnGUIEvent( id, desk );
577 SUIT_MessageBox::critical( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_LIB_NOT_FOUND" ), tr( "GEOM_BUT_OK" ) );
581 //=================================================================================
582 // function : GeometryGUI::OnKeyPress()
583 // purpose : Called when any key is pressed by user [static]
584 //=================================================================================
585 void GeometryGUI::OnKeyPress( SUIT_ViewWindow* win, QKeyEvent* pe )
589 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it ) {
590 SUIT_Application* anApp = application();
592 bOk = bOk && it.value()->OnKeyPress( pe, anApp->desktop(), win );
598 //=================================================================================
599 // function : GeometryGUI::OnMouseMove()
600 // purpose : Manages mouse move events [static]
601 //=================================================================================
602 void GeometryGUI::OnMouseMove( SUIT_ViewWindow* win, QMouseEvent* pe )
606 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it ) {
607 SUIT_Application* anApp = application();
609 bOk = bOk && it.value()->OnMouseMove( pe, anApp->desktop(), win );
615 //=================================================================================
616 // function : GeometryGUI::0nMousePress()
617 // purpose : Manage mouse press events [static]
618 //=================================================================================
619 void GeometryGUI::OnMousePress( SUIT_ViewWindow* win, QMouseEvent* pe )
622 // OnMousePress() should return false if this event should be processed further
623 // (see OCCViewer_Viewer3d::onMousePress() for explanation)
624 bool processed = false;
625 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it ) {
626 SUIT_Application* anApp = application();
628 processed = processed || it.value()->OnMousePress( pe, anApp->desktop(), win );
634 static void UpdateVtkSelection()
636 QPtrList<SUIT_ViewWindow> winList = application()->desktop()->windows();
637 SUIT_ViewWindow* win = 0;
638 for ( win = winList.first(); win; win = winList.next() ) {
639 if ( win->getViewManager()->getTypeView() == VIEW_VTK ) {
640 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( window );
642 SVTK_RenderWindowInteractor* anInteractor = vw->getRWInteractor();
643 anInteractor->SetSelectionProp();
644 anInteractor->SetSelectionTolerance();
645 SVTK_InteractorStyleSALOME* aStyle = anInteractor->GetInteractorStyleSALOME();
647 aStyle->setPreselectionProp();
654 //=================================================================================
655 // function : GeometryGUI::SetSettings()
656 // purpose : Called when GEOM module is activated [static]
657 //=================================================================================
658 bool GeometryGUI::SetSettings()
660 QMenuBar* Mb = parent->getMainMenuBar();
661 SUIT_Study* ActiveStudy = application()->activeStudy();
663 // Wireframe or Shading
665 SUIT_ViewWindow* window = application()->desktop()->activeWindow();
666 bool ViewOCC = ( window && window->getViewManager()->getType() == VIEW_OCC );
667 bool ViewVTK = ( window && window->getViewManager()->getType() == VIEW_VTK );
669 OCCViewer_ViewManager* vm = dynamic_cast<OCCViewer_ViewManager*>( window->getViewManager() );
671 Handle(AIS_InteractiveContext) ic = vm->getOCCViewer()->getAISContext();
672 DisplayMode = ic->DisplayMode();
675 else if ( ViewVTK ) {
676 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( window );
678 SVTK_RenderWindowInteractor* myRenderInter = vw->getRWInteractor();
679 DisplayMode = myRenderInter->GetDisplayMode();
683 if( DisplayMode == 1 )
685 Mb->changeItem( 211, tr( "GEOM_MEN_WIREFRAME" ) );
687 Mb->changeItem( 211, tr( "GEOM_MEN_SHADING" ) );
690 // Add in Study - !!!ALWAYS TRUE!!! /////// VSR : TO BE REMOVED
691 QString AddInStudy = QAD_CONFIG->getSetting("Geometry:SettingsAddInStudy");
692 int Settings_AddInStudy;
693 // if(!AddInStudy.isEmpty())
694 // Settings_AddInStudy = AddInStudy.toInt();
697 Settings_AddInStudy = 1;
698 Mb->setItemChecked(411, Settings_AddInStudy);
701 QString S = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
703 QAD_CONFIG->addSetting("Geometry:SettingsGeomStep", "100");
706 int count = ActiveStudy->getStudyFramesCount();
707 for(int i = 0; i < count; i++) {
708 if(ActiveStudy->getStudyFrame(i)->getTypeView() == VIEW_OCC) {
709 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)ActiveStudy->getStudyFrame(i)->getRightFrame()->getViewFrame())->getViewer();
710 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
712 QString IsoU = QAD_CONFIG->getSetting("Geometry:SettingsIsoU");
713 QString IsoV = QAD_CONFIG->getSetting("Geometry:SettingsIsoV");
715 ic->DefaultDrawer()->UIsoAspect()->SetNumber(IsoU.toInt());
717 ic->DefaultDrawer()->VIsoAspect()->SetNumber(IsoV.toInt());
723 // PAL5356: update VTK selection
724 ::UpdateVtkSelection();
727 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
728 bOk = bOk && it.data()->SetSettings( parent );
730 // MZN: Enable/disable "Clipping range" menu item(from GEOM_CLIPPING variable)
731 if (getenv( "GEOM_CLIPPING" ) == NULL)
733 QMenuItem* mi = Mb->findItem(50);
734 if (mi && mi->popup())
735 mi->popup()->removeItem(507);
742 //=======================================================================
743 // function : createGeomAction
745 //=======================================================================
746 void GeometryGUI::createGeomAction( const int id, const QString& po_id, const QString& icon_id, const int key, const bool toggle )
749 QWidget* parent = application()->desktop();
750 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
752 if ( icon_id.length() )
753 pix = resMgr->loadPixmap( "GEOM", tr( icon_id.toLatin1().constData() ) );
755 pix = resMgr->loadPixmap( "GEOM", tr( (QString( "ICO_" )+po_id).toLatin1().constData() ), false );
759 QString tooltip = tr( (QString( "TOP_" )+po_id).toLatin1().constData() ),
760 menu = tr( (QString( "MEN_" )+po_id).toLatin1().constData() ),
761 status_bar = tr( (QString( "STB_" )+po_id).toLatin1().constData() );
763 createAction( id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT( OnGUIEvent() ) );
768 //=======================================================================
769 // function : GeometryGUI::initialize()
770 // purpose : Called when GEOM module is created
771 //=======================================================================
772 void GeometryGUI::initialize( CAM_Application* app )
774 SalomeApp_Module::initialize( app );
776 // ----- create actions --------------
778 createGeomAction( 111, "IMPORT", "", (CTRL + Key_I) );
779 createGeomAction( 121, "EXPORT", "", (CTRL + Key_E) );
781 createGeomAction( 33, "DELETE", "", Qt::Key_Delete );
783 createGeomAction( 4011, "POINT" );
784 createGeomAction( 4012, "LINE" );
785 createGeomAction( 4013, "CIRCLE" );
786 createGeomAction( 4014, "ELLIPSE" );
787 createGeomAction( 4015, "ARC" );
788 createGeomAction( 4019, "CURVE" );
789 createGeomAction( 4016, "VECTOR" );
790 createGeomAction( 4017, "PLANE" );
791 // createGeomAction( 4018, "WORK_PLANE" ); DEPRECATED
792 createGeomAction( 4020, "LOCAL_CS" );
794 createGeomAction( 4021, "BOX" );
795 createGeomAction( 4022, "CYLINDER" );
796 createGeomAction( 4023, "SPHERE" );
797 createGeomAction( 4024, "TORUS" );
798 createGeomAction( 4025, "CONE" );
799 createGeomAction( 4026, "FACE" );
800 createGeomAction( 4027, "DISK" );
802 createGeomAction( 4031, "EXTRUSION" );
803 createGeomAction( 4032, "REVOLUTION" );
804 createGeomAction( 4033, "FILLING" );
805 createGeomAction( 4034, "PIPE" );
807 createGeomAction( 800, "GROUP_CREATE" );
808 createGeomAction( 801, "GROUP_EDIT" );
810 createGeomAction( 5029, "RELOAD_IMPORTED" );
812 createGeomAction( 9997, "Q_FACE" );
813 createGeomAction( 9999, "HEX_SOLID" );
815 createGeomAction( 404, "SKETCH" );
816 createGeomAction( 405, "3DSKETCH" );
817 createGeomAction( 407, "EXPLODE" );
819 createGeomAction( 4081, "EDGE" );
820 createGeomAction( 4082, "WIRE" );
821 createGeomAction( 4083, "FACE" );
822 createGeomAction( 4084, "SHELL" );
823 createGeomAction( 4085, "SOLID" );
824 createGeomAction( 4086, "COMPOUND" );
826 createGeomAction( 5011, "FUSE" );
827 createGeomAction( 5012, "COMMON" );
828 createGeomAction( 5013, "CUT" );
829 createGeomAction( 5014, "SECTION" );
831 createGeomAction( 5021, "TRANSLATION" );
832 createGeomAction( 5022, "ROTATION" );
833 createGeomAction( 5023, "MODIFY_LOCATION" );
834 createGeomAction( 5024, "MIRROR" );
835 createGeomAction( 5025, "SCALE" );
836 createGeomAction( 5026, "OFFSET" );
837 createGeomAction( 5027, "MUL_TRANSLATION" );
838 createGeomAction( 5028, "MUL_ROTATION" );
840 createGeomAction( 503, "PARTITION" );
841 createGeomAction( 504, "ARCHIMEDE" );
842 createGeomAction( 505, "FILLET" );
843 createGeomAction( 506, "CHAMFER" );
844 //createGeomAction( 507, "CLIPPING" );
845 createGeomAction( 508, "GET_SHAPES_ON_SHAPES" );
846 createGeomAction( 510, "FILLET_1D" );
847 createGeomAction( 509, "FILLET_2D" );
849 createGeomAction( 9998, "MUL_TRANSFORM" );
850 createGeomAction( 9995, "EXPLODE_BLOCKS" );
851 createGeomAction( 99991, "PROPAGATE" );
853 createGeomAction( 601, "SEWING" );
854 createGeomAction( 602, "GLUE_FACES" );
855 createGeomAction( 603, "SUPPRESS_FACES" );
856 createGeomAction( 604, "SUPPERSS_HOLES" );
857 createGeomAction( 605, "SHAPE_PROCESS" );
858 createGeomAction( 606, "CLOSE_CONTOUR" );
859 createGeomAction( 607, "SUPPRESS_INT_WIRES" );
860 createGeomAction( 608, "POINT_ON_EDGE" );
861 createGeomAction( 609, "CHECK_FREE_BNDS" );
862 createGeomAction( 610, "CHECK_FREE_FACES" );
863 createGeomAction( 611, "CHANGE_ORIENTATION" );
864 createGeomAction( 612, "REMOVE_EXTRA_EDGES" );
866 createGeomAction( 708, "POINT_COORDS" );
867 createGeomAction( 701, "BASIC_PROPS" );
868 createGeomAction( 702, "MASS_CENTER" );
869 createGeomAction( 703, "INERTIA" );
870 createGeomAction( 704, "NORMALE" );
871 createGeomAction( 7041, "BND_BOX" );
872 createGeomAction( 7042, "MIN_DIST" );
873 createGeomAction( 7043, "MEASURE_ANGLE" );
875 createGeomAction( 705, "TOLERANCE" );
876 createGeomAction( 706, "WHAT_IS" );
877 createGeomAction( 707, "CHECK" );
878 createGeomAction( 7072, "CHECK_COMPOUND" );
880 #ifdef _DEBUG_ // PAL16821
881 createGeomAction( 5103, "CHECK_GEOMETRY" );
883 createGeomAction( 412, "SHADING_COLOR" );
885 createGeomAction( 211, "SHADING" );
886 createGeomAction( 212, "DISPLAY_ALL" );
887 createGeomAction( 214, "ERASE_ALL" );
888 createGeomAction( 216, "DISPLAY" );
889 createGeomAction( 218, "VECTOR_MODE");
890 createGeomAction( 2171, "VERTEX_SEL_ONLY" ,"", 0, true );
891 createGeomAction( 2172, "EDGE_SEL_ONLY", "", 0, true );
892 createGeomAction( 2173, "WIRE_SEL_ONLY", "", 0, true );
893 createGeomAction( 2174, "FACE_SEL_ONLY", "", 0, true );
894 createGeomAction( 2175, "SHELL_SEL_ONLY", "", 0, true );
895 createGeomAction( 2176, "SOLID_SEL_ONLY", "", 0, true );
896 createGeomAction( 2177, "COMPOUND_SEL_ONLY", "", 0, true );
897 createGeomAction( 2178, "ALL_SEL_ONLY", "", 0, true );
898 createGeomAction( 213, "DISPLAY_ONLY" );
899 createGeomAction( 215, "ERASE" );
901 createGeomAction( 901, "POP_RENAME", "", Qt::Key_F2 );
902 createGeomAction( 80311, "POP_WIREFRAME", "", 0, true );
903 createGeomAction( 80312, "POP_SHADING", "", 0, true );
904 createGeomAction( 80313, "POP_VECTORS", "", 0, true );
905 createGeomAction( 8032, "POP_COLOR" );
906 createGeomAction( 8033, "POP_TRANSPARENCY" );
907 createGeomAction( 8034, "POP_ISOS" );
908 createGeomAction( 8035, "POP_AUTO_COLOR" );
909 createGeomAction( 8036, "POP_DISABLE_AUTO_COLOR" );
910 createGeomAction( 8001, "POP_CREATE_GROUP" );
911 createGeomAction( 8037, "POP_SHOW_CHILDREN" );
912 createGeomAction( 8038, "POP_HIDE_CHILDREN" );
914 // make wireframe-shading items to be exclusive (only one at a time is selected)
915 //QActionGroup* dispModeGr = new QActionGroup( this, "", true );
916 //dispModeGr->add( action( 80311 ) );
917 //dispModeGr->add( action( 80312 ) );
918 // ---- create menu --------------------------
920 int fileId = createMenu( tr( "MEN_FILE" ), -1, -1 );
921 createMenu( separator(), fileId, 10 );
922 createMenu( 111, fileId, 10 );
923 createMenu( 121, fileId, 10 );
924 createMenu( separator(), fileId, -1 );
926 int editId = createMenu( tr( "MEN_EDIT" ), -1, -1 );
927 createMenu( 33, editId, -1 );
929 int newEntId = createMenu( tr( "MEN_NEW_ENTITY" ), -1, -1, 10 );
931 int basicId = createMenu( tr( "MEN_BASIC" ), newEntId, -1 );
932 createMenu( 4011, basicId, -1 );
933 createMenu( 4012, basicId, -1 );
934 createMenu( 4013, basicId, -1 );
935 createMenu( 4014, basicId, -1 );
936 createMenu( 4015, basicId, -1 );
937 createMenu( 4019, basicId, -1 );
938 createMenu( separator(), basicId, -1 );
939 createMenu( 4016, basicId, -1 );
940 createMenu( 4017, basicId, -1 );
941 // createMenu( 4018, basicId, -1 ); DEPRECATED
942 createMenu( 4020, basicId, -1 );
944 int primId = createMenu( tr( "MEN_PRIMITIVES" ), newEntId, -1 );
945 createMenu( 4021, primId, -1 );
946 createMenu( 4022, primId, -1 );
947 createMenu( 4023, primId, -1 );
948 createMenu( 4024, primId, -1 );
949 createMenu( 4025, primId, -1 );
950 createMenu( 4026, primId, -1 );
951 createMenu( 4027, primId, -1 );
953 int genId = createMenu( tr( "MEN_GENERATION" ), newEntId, -1 );
954 createMenu( 4031, genId, -1 );
955 createMenu( 4032, genId, -1 );
956 createMenu( 4033, genId, -1 );
957 createMenu( 4034, genId, -1 );
958 createMenu( separator(), newEntId, -1 );
960 int groupId = createMenu( tr( "MEN_GROUP" ), newEntId, -1 );
961 createMenu( 800, groupId, -1 );
962 createMenu( 801, groupId, -1 );
963 createMenu( separator(), newEntId, -1 );
965 int blocksId = createMenu( tr( "MEN_BLOCKS" ), newEntId, -1 );
966 createMenu( 9997, blocksId, -1 );
967 createMenu( 9999, blocksId, -1 );
969 createMenu( separator(), newEntId, -1 );
970 createMenu( 404, newEntId, -1 );
971 createMenu( 405, newEntId, -1 );
972 createMenu( separator(), newEntId, -1 );
973 createMenu( 407, newEntId, -1 );
975 int buildId = createMenu( tr( "MEN_BUILD" ), newEntId, -1 );
976 createMenu( 4081, buildId, -1 );
977 createMenu( 4082, buildId, -1 );
978 createMenu( 4083, buildId, -1 );
979 createMenu( 4084, buildId, -1 );
980 createMenu( 4085, buildId, -1 );
981 createMenu( 4086, buildId, -1 );
983 int operId = createMenu( tr( "MEN_OPERATIONS" ), -1, -1, 10 );
985 int boolId = createMenu( tr( "MEN_BOOLEAN" ), operId, -1 );
986 createMenu( 5011, boolId, -1 );
987 createMenu( 5012, boolId, -1 );
988 createMenu( 5013, boolId, -1 );
989 createMenu( 5014, boolId, -1 );
991 int transId = createMenu( tr( "MEN_TRANSFORMATION" ), operId, -1 );
992 createMenu( 5021, transId, -1 );
993 createMenu( 5022, transId, -1 );
994 createMenu( 5023, transId, -1 );
995 createMenu( 5024, transId, -1 );
996 createMenu( 5025, transId, -1 );
997 createMenu( 5026, transId, -1 );
998 createMenu( separator(), transId, -1 );
999 createMenu( 5027, transId, -1 );
1000 createMenu( 5028, transId, -1 );
1002 createMenu( 503, operId, -1 );
1003 createMenu( 504, operId, -1 );
1004 createMenu( 508, operId, -1 );
1005 createMenu( separator(), operId, -1 );
1006 createMenu( 510, transId, -1 );
1007 createMenu( 509, transId, -1 );
1008 createMenu( 505, transId, -1 );
1009 createMenu( 506, transId, -1 );
1010 //createMenu( 507, transId, -1 );
1012 int blockId = createMenu( tr( "MEN_BLOCKS" ), operId, -1 );
1013 createMenu( 9998, blockId, -1 );
1014 createMenu( 9995, blockId, -1 );
1015 createMenu( 99991, blockId, -1 );
1017 int repairId = createMenu( tr( "MEN_REPAIR" ), -1, -1, 10 );
1018 createMenu( 605, repairId, -1 );
1019 createMenu( 603, repairId, -1 );
1020 createMenu( 606, repairId, -1 );
1021 createMenu( 607, repairId, -1 );
1022 createMenu( 604, repairId, -1 );
1023 createMenu( 601, repairId, -1 );
1024 createMenu( 602, repairId, -1 );
1025 createMenu( 608, repairId, -1 );
1026 //createMenu( 609, repairId, -1 );
1027 //createMenu( 610, repairId, -1 );
1028 createMenu( 611, repairId, -1 );
1029 createMenu( 612, repairId, -1 );
1031 int measurId = createMenu( tr( "MEN_MEASURES" ), -1, -1, 10 );
1032 createMenu( 708, measurId, -1 );
1033 createMenu( 701, measurId, -1 );
1034 createMenu( separator(), measurId, -1 );
1035 createMenu( 702, measurId, -1 );
1036 createMenu( 703, measurId, -1 );
1037 createMenu( 704, measurId, -1 );
1038 // NPAL16572: move "Check free boundaries" and "Check free faces" from "Repair" to "Measure"
1039 createMenu( separator(), measurId, -1 );
1040 createMenu( 609, measurId, -1 );
1041 createMenu( 610, measurId, -1 );
1043 createMenu( separator(), measurId, -1 );
1045 int dimId = createMenu( tr( "MEN_DIMENSIONS" ), measurId, -1 );
1046 createMenu( 7041, dimId, -1 );
1047 createMenu( 7042, dimId, -1 );
1048 createMenu( 7043, dimId, -1 );
1049 createMenu( separator(), measurId, -1 );
1051 createMenu( 705, measurId, -1 );
1052 createMenu( separator(), measurId, -1 );
1053 createMenu( 706, measurId, -1 );
1054 createMenu( 707, measurId, -1 );
1055 createMenu( 7072, measurId, -1 );
1057 #ifdef _DEBUG_ // PAL16821
1058 int toolsId = createMenu( tr( "MEN_TOOLS" ), -1, -1, 50 );
1059 createMenu( separator(), toolsId, -1 );
1060 createMenu( 5103, toolsId, -1 );
1062 //int prefId = createMenu( tr( "MEN_PREFERENCES" ), -1, -1, 50 );
1063 //createMenu( separator(), prefId, -1 );
1064 //int geomId = createMenu( tr( "MEN_PREFERENCES_GEOM" ), prefId, -1 );
1065 //createMenu( 412, geomId, -1 );
1066 //createMenu( separator(), prefId, -1 );
1068 int viewId = createMenu( tr( "MEN_VIEW" ), -1, -1 );
1069 createMenu( separator(), viewId, -1 );
1071 int dispmodeId = createMenu( tr( "MEN_DISPLAY_MODE" ), viewId, -1 );
1072 createMenu( 211, dispmodeId, -1 );
1073 createMenu( separator(), dispmodeId, -1 );
1074 createMenu( 218, dispmodeId, -1 );
1076 createMenu( separator(), viewId, -1 );
1077 createMenu( 212, viewId, -1 );
1078 createMenu( 214, viewId, -1 );
1079 createMenu( separator(), viewId, -1 );
1083 because of these items are accessible through object browser and viewers
1084 we have removed they from main menu
1086 createMenu( 216, viewId, -1 );
1087 createMenu( 213, viewId, -1 );
1088 createMenu( 215, viewId, -1 );
1091 // ---- create toolbars --------------------------
1093 int basicTbId = createTool( tr( "TOOL_BASIC" ) );
1094 createTool( 4011, basicTbId );
1095 createTool( 4012, basicTbId );
1096 createTool( 4013, basicTbId );
1097 createTool( 4014, basicTbId );
1098 createTool( 4015, basicTbId );
1099 createTool( 4019, basicTbId );
1100 createTool( 4016, basicTbId );
1101 createTool( 4017, basicTbId );
1102 // createTool( 4018, basicTbId ); DEPRECATED
1103 createTool( 4020, basicTbId );
1105 int primTbId = createTool( tr( "TOOL_PRIMITIVES" ) );
1106 createTool( 4021, primTbId );
1107 createTool( 4022, primTbId );
1108 createTool( 4023, primTbId );
1109 createTool( 4024, primTbId );
1110 createTool( 4025, primTbId );
1111 createTool( 4026, primTbId );
1112 createTool( 4027, primTbId );
1114 int boolTbId = createTool( tr( "TOOL_BOOLEAN" ) );
1115 createTool( 5011, boolTbId );
1116 createTool( 5012, boolTbId );
1117 createTool( 5013, boolTbId );
1118 createTool( 5014, boolTbId );
1120 int genTbId = createTool( tr( "TOOL_GENERATION" ) );
1121 createTool( 4031, genTbId );
1122 createTool( 4032, genTbId );
1123 createTool( 4033, genTbId );
1124 createTool( 4034, genTbId );
1126 int transTbId = createTool( tr( "TOOL_TRANSFORMATION" ) );
1127 createTool( 5021, transTbId );
1128 createTool( 5022, transTbId );
1129 createTool( 5023, transTbId );
1130 createTool( 5024, transTbId );
1131 createTool( 5025, transTbId );
1132 createTool( 5026, transTbId );
1133 createTool( separator(), transTbId );
1134 createTool( 5027, transTbId );
1135 createTool( 5028, transTbId );
1137 // ---- create popup menus --------------------------
1139 QString clientOCCorVTK = "(client='OCCViewer' or client='VTKViewer')";
1140 QString clientOCCorVTK_AndSomeVisible = clientOCCorVTK + " and selcount>0 and isVisible";
1142 QString clientOCCorVTKorOB = "(client='ObjectBrowser' or client='OCCViewer' or client='VTKViewer')";
1143 QString clientOCCorVTKorOB_AndSomeVisible = clientOCCorVTKorOB + " and selcount>0 and isVisible";
1145 QString autoColorPrefix =
1146 "(client='ObjectBrowser' or client='OCCViewer') and type='Shape' and selcount=1 and isOCC=true";
1148 QtxPopupMgr* mgr = popupMgr();
1149 mgr->insert( action( 901 ), -1, -1 ); // rename
1150 mgr->setRule( action( 901 ), QString("$type in {'Shape' 'Group'} and selcount=1"), QtxPopupMgr::VisibleRule );
1151 mgr->insert( action( 33 ), -1, -1 ); // delete
1152 mgr->setRule( action( 33 ), QString("$type in {'Shape' 'Group'} and selcount>0"), QtxPopupMgr::VisibleRule );
1153 mgr->insert( action( 8001 ), -1, -1 ); // create group
1154 mgr->setRule( action( 8001 ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and isOCC=true"), QtxPopupMgr::VisibleRule );
1155 mgr->insert( action( 8037 ), -1, -1 ); // show children
1156 mgr->setRule( action( 8037 ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and hasHiddenChildren=true"), QtxPopupMgr::VisibleRule );
1157 mgr->insert( action( 8038 ), -1, -1 ); // hide children
1158 mgr->setRule( action( 8038 ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and hasShownChildren=true"), QtxPopupMgr::VisibleRule );
1159 mgr->insert( action( 801 ), -1, -1 ); // edit group
1160 mgr->setRule( action( 801 ), QString("client='ObjectBrowser' and type='Group' and selcount=1 and isOCC=true"), QtxPopupMgr::VisibleRule );
1161 mgr->insert( separator(), -1, -1 ); // -----------
1162 dispmodeId = mgr->insert( tr( "MEN_DISPLAY_MODE" ), -1, -1 ); // display mode menu
1163 mgr->insert( action( 80311 ), dispmodeId, -1 ); // wireframe
1164 mgr->setRule( action( 80311 ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1165 mgr->setRule( action( 80311 ), clientOCCorVTK + " and displaymode='Wireframe'", QtxPopupMgr::ToggleRule );
1166 mgr->insert( action( 80312 ), dispmodeId, -1 ); // shading
1167 mgr->setRule( action( 80312 ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1168 mgr->setRule( action( 80312 ), clientOCCorVTK + " and displaymode='Shading'", QtxPopupMgr::ToggleRule );
1169 mgr->insert( separator(), dispmodeId, -1 );
1170 mgr->insert( action( 80313 ), dispmodeId, -1 ); // vectors
1171 mgr->setRule( action( 80313 ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1172 mgr->setRule( action( 80313 ), clientOCCorVTK + " and isVectorsMode", QtxPopupMgr::ToggleRule );
1173 mgr->insert( separator(), -1, -1 ); // -----------
1174 mgr->insert( action( 8032 ), -1, -1 ); // color
1175 mgr->setRule( action( 8032 ), clientOCCorVTKorOB_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1176 mgr->insert( action( 8033 ), -1, -1 ); // transparency
1177 mgr->setRule( action( 8033 ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1178 mgr->insert( action( 8034 ), -1, -1 ); // isos
1179 mgr->setRule( action( 8034 ), clientOCCorVTK_AndSomeVisible + " and selcount>0 and isVisible", QtxPopupMgr::VisibleRule );
1180 mgr->insert( separator(), -1, -1 ); // -----------
1181 mgr->insert( action( 8035 ), -1, -1 ); // auto color
1182 mgr->setRule( action( 8035 ), autoColorPrefix + " and isAutoColor=false", QtxPopupMgr::VisibleRule );
1183 mgr->insert( action( 8036 ), -1, -1 ); // disable auto color
1184 mgr->setRule( action( 8036 ), autoColorPrefix + " and isAutoColor=true", QtxPopupMgr::VisibleRule );
1185 mgr->insert( separator(), -1, -1 ); // -----------
1188 QString canDisplay = "($component={'GEOM'}) and (selcount>0) and ({true} in $canBeDisplayed) ",
1189 onlyComponent = "((type='Component') and selcount=1)",
1190 rule = canDisplay + "and ((($type in {%1}) and( %2 )) or " + onlyComponent + ")",
1191 types = "'Shape' 'Group'";
1193 mgr->insert( action( 216 ), -1, -1 ); // display
1194 mgr->setRule( action( 216 ), rule.arg( types ).arg( "not isVisible" ), QtxPopupMgr::VisibleRule );
1196 mgr->insert( action( 215 ), -1, -1 ); // erase
1197 mgr->setRule( action( 215 ), rule.arg( types ).arg( "isVisible" ), QtxPopupMgr::VisibleRule );
1199 mgr->insert( action( 214 ), -1, -1 ); // erase All
1200 mgr->setRule( action( 214 ), clientOCCorVTK, QtxPopupMgr::VisibleRule );
1202 QString selectOnly = "(client='OCCViewer' or client='VTKViewer') and (selcount=0)";
1204 int selectolnyId = mgr->insert( tr("MEN_SELECT_ONLY"), -1, -1); //select only menu
1205 mgr->insert( action(2171), selectolnyId, -1); //Vertex
1206 mgr->setRule(action(2171), selectOnly, QtxPopupMgr::VisibleRule);
1207 mgr->setRule(action(2171), selectOnly + " and selectionmode='VERTEX'", QtxPopupMgr::ToggleRule);
1208 mgr->insert( action(2172), selectolnyId, -1); //Edge
1209 mgr->setRule(action(2172), selectOnly, QtxPopupMgr::VisibleRule);
1210 mgr->setRule(action(2172), selectOnly + " and selectionmode='EDGE'", QtxPopupMgr::ToggleRule);
1211 mgr->insert( action(2173), selectolnyId, -1); //Wire
1212 mgr->setRule(action(2173), selectOnly, QtxPopupMgr::VisibleRule);
1213 mgr->setRule(action(2173), selectOnly + " and selectionmode='WIRE'", QtxPopupMgr::ToggleRule);
1214 mgr->insert( action(2174), selectolnyId, -1); //Face
1215 mgr->setRule(action(2174), selectOnly, QtxPopupMgr::VisibleRule);
1216 mgr->setRule(action(2174), selectOnly + " and selectionmode='FACE'", QtxPopupMgr::ToggleRule);
1217 mgr->insert( action(2175), selectolnyId, -1); //Shell
1218 mgr->setRule(action(2175), selectOnly, QtxPopupMgr::VisibleRule);
1219 mgr->setRule(action(2175), selectOnly + " and selectionmode='SHELL'", QtxPopupMgr::ToggleRule);
1220 mgr->insert( action(2176), selectolnyId, -1); //Solid
1221 mgr->setRule(action(2176), selectOnly, QtxPopupMgr::VisibleRule);
1222 mgr->setRule(action(2176), selectOnly + " and selectionmode='SOLID'", QtxPopupMgr::ToggleRule);
1223 mgr->insert( action(2177), selectolnyId, -1); //Compound
1224 mgr->setRule(action(2177), selectOnly, QtxPopupMgr::VisibleRule);
1225 mgr->setRule(action(2177), selectOnly + " and selectionmode='COMPOUND'", QtxPopupMgr::ToggleRule);
1226 mgr->insert( separator(), selectolnyId, -1);
1227 mgr->insert( action(2178), selectolnyId, -1); //Clear selection filter
1228 mgr->setRule(action(2178), selectOnly, QtxPopupMgr::VisibleRule);
1229 mgr->setRule(action(2178), selectOnly + " and selectionmode='ALL'", QtxPopupMgr::ToggleRule);
1230 mgr->insert( action( 213 ), -1, -1 ); // display only
1231 mgr->setRule( action( 213 ), rule.arg( types ).arg( "true" ), QtxPopupMgr::VisibleRule );
1232 mgr->insert( separator(), -1, -1 );
1234 mgr->hide( mgr->actionId( action( myEraseAll ) ) );
1237 //=======================================================================
1238 // function : GeometryGUI::activateModule()
1239 // purpose : Called when GEOM module is activated
1240 //=======================================================================
1241 bool GeometryGUI::activateModule( SUIT_Study* study )
1243 if ( CORBA::is_nil( myComponentGeom ) )
1246 bool res = SalomeApp_Module::activateModule( study );
1251 setMenuShown( true );
1252 setToolShown( true );
1254 connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1255 this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1257 // Reset actions accelerator keys
1258 //action(111)->setAccel(QKeySequence(CTRL + Key_I)); // Import
1259 //action(121)->setAccel(QKeySequence(CTRL + Key_E)); // Export
1260 action(111)->setEnabled( true ); // Import: CTRL + Key_I
1261 action(121)->setEnabled( true ); // Export: CTRL + Key_E
1262 action( 33)->setEnabled( true ); // Delete: Key_Delete
1263 action(901)->setEnabled( true ); // Rename: Key_F2
1265 GUIMap::Iterator it;
1266 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1267 it.value()->activate( application()->desktop() );
1269 LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1271 SUIT_ViewManager* vm;
1272 ViewManagerList OCCViewManagers, VTKViewManagers;
1274 application()->viewManagers( OCCViewer_Viewer::Type(), OCCViewManagers );
1275 QListIterator<SUIT_ViewManager*> itOCC( OCCViewManagers );
1276 while ( itOCC.hasNext() && (vm = itOCC.next()) )
1277 myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1279 application()->viewManagers( SVTK_Viewer::Type(), VTKViewManagers );
1280 QListIterator<SUIT_ViewManager*> itVTK( VTKViewManagers );
1281 while ( itVTK.hasNext() && (vm = itVTK.next()) )
1282 myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
1285 SALOME_ListIO selected;
1286 sm->selectedObjects( selected );
1287 sm->clearSelected();
1289 // disable OCC selectors
1290 getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1291 QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1292 while ( itOCCSel.hasNext() )
1293 if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1294 sr->setEnabled(true);
1296 // disable VTK selectors
1297 getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
1298 QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1299 while ( itVTKSel.hasNext() )
1300 if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1301 sr->setEnabled(true);
1303 sm->setSelectedObjects( selected, true ); //NPAL 19674
1305 QMenu* viewMenu = menuMgr()->findMenu( STD_Application::MenuViewId );
1307 connect( viewMenu, SIGNAL( aboutToShow() ), this, SLOT( onViewAboutToShow() ) );
1313 //=======================================================================
1314 // function : GeometryGUI::deactivateModule()
1315 // purpose : Called when GEOM module is deactivated
1316 //=======================================================================
1317 bool GeometryGUI::deactivateModule( SUIT_Study* study )
1319 QMenu* viewMenu = menuMgr()->findMenu( STD_Application::MenuViewId );
1321 disconnect( viewMenu, SIGNAL( aboutToShow() ), this, SLOT( onViewAboutToShow() ) );
1323 setMenuShown( false );
1324 setToolShown( false );
1326 disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1327 this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1329 EmitSignalCloseAllDialogs();
1331 GUIMap::Iterator it;
1332 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1333 it.value()->deactivate();
1335 // Unset actions accelerator keys
1336 //action(111)->setAccel(QKeySequence()); // Import
1337 //action(121)->setAccel(QKeySequence()); // Export
1338 action(111)->setEnabled( false ); // Import: CTRL + Key_I
1339 action(121)->setEnabled( false ); // Export: CTRL + Key_E
1340 action( 33)->setEnabled( false ); // Delete: Key_Delete
1341 action(901)->setEnabled( false ); // Rename: Key_F2
1343 qDeleteAll(myOCCSelectors);
1344 myOCCSelectors.clear();
1345 getApp()->selectionMgr()->setEnabled( true, OCCViewer_Viewer::Type() );
1347 qDeleteAll(myVTKSelectors);
1348 myVTKSelectors.clear();
1349 getApp()->selectionMgr()->setEnabled( true, SVTK_Viewer::Type() );
1351 return SalomeApp_Module::deactivateModule( study );
1354 //=======================================================================
1355 // function : GeometryGUI::BuildPresentation()
1357 //=======================================================================
1358 void GeometryGUI::BuildPresentation( const Handle(SALOME_InteractiveObject)& io, SUIT_ViewWindow* win )
1360 //GEOM_Displayer().Display( io, false, win );
1363 //=======================================================================
1364 // function : onWindowActivated()
1365 // purpose : update menu items' status - disable non-OCC-viewer-compatible actions
1366 //=======================================================================
1367 void GeometryGUI::onWindowActivated( SUIT_ViewWindow* win )
1372 const bool ViewOCC = ( win->getViewManager()->getType() == OCCViewer_Viewer::Type() );
1373 //const bool ViewVTK = ( win->getViewManager()->getType() == SVTK_Viewer::Type() );
1375 // disable non-OCC viewframe menu commands
1376 // action( 404 )->setEnabled( ViewOCC ); // SKETCHER
1377 action( 603 )->setEnabled( ViewOCC ); // SuppressFace
1378 action( 604 )->setEnabled( ViewOCC ); // SuppressHole
1379 action( 606 )->setEnabled( ViewOCC ); // CloseContour
1380 action( 607 )->setEnabled( ViewOCC ); // RemoveInternalWires
1381 action( 608 )->setEnabled( ViewOCC ); // AddPointOnEdge
1382 // action( 609 )->setEnabled( ViewOCC ); // Free boundaries
1384 action( 800 )->setEnabled( ViewOCC ); // Create Group
1385 action( 801 )->setEnabled( ViewOCC ); // Edit Group
1387 action( 9998 )->setEnabled( ViewOCC ); // MENU BLOCKS - MULTI-TRANSFORMATION
1390 void GeometryGUI::windows( QMap<int, int>& mappa ) const
1392 mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
1393 mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
1396 void GeometryGUI::viewManagers( QStringList& lst ) const
1398 lst.append( OCCViewer_Viewer::Type() );
1401 void GeometryGUI::onViewManagerAdded( SUIT_ViewManager* vm )
1403 if ( vm->getType() == OCCViewer_Viewer::Type() )
1405 qDebug( "connect" );
1406 connect( vm, SIGNAL( keyPress ( SUIT_ViewWindow*, QKeyEvent* ) ),
1407 this, SLOT( OnKeyPress( SUIT_ViewWindow*, QKeyEvent* ) ) );
1408 connect( vm, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
1409 this, SLOT( OnMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
1410 connect( vm, SIGNAL( mouseMove ( SUIT_ViewWindow*, QMouseEvent* ) ),
1411 this, SLOT( OnMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1414 LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1415 myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1417 // disable OCC selectors
1418 getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1419 QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1420 while ( itOCCSel.hasNext() )
1421 if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1422 sr->setEnabled(true);
1424 else if ( vm->getType() == SVTK_Viewer::Type() )
1426 LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1427 myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
1429 // disable VTK selectors
1430 getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
1431 QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1432 while ( itVTKSel.hasNext() )
1433 if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1434 sr->setEnabled(true);
1438 void GeometryGUI::onViewManagerRemoved( SUIT_ViewManager* vm )
1440 SUIT_ViewModel* viewer = vm->getViewModel();
1441 if ( vm->getType() == OCCViewer_Viewer::Type() )
1443 QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1444 while ( itOCCSel.hasNext() )
1445 if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1446 if ( sr->viewer() == viewer )
1448 delete myOCCSelectors.takeAt( myOCCSelectors.indexOf( sr ) );
1452 if ( vm->getType() == SVTK_Viewer::Type() )
1454 QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1455 while ( itVTKSel.hasNext() )
1456 if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1457 if ( sr->viewer() == viewer )
1459 delete myVTKSelectors.takeAt( myVTKSelectors.indexOf( sr ) );
1465 QString GeometryGUI::engineIOR() const
1467 if ( !CORBA::is_nil( GetGeomGen() ) )
1468 return QString( getApp()->orb()->object_to_string( GetGeomGen() ) );
1472 LightApp_Selection* GeometryGUI::createSelection() const
1474 return new GEOMGUI_Selection();
1477 void GeometryGUI::contextMenuPopup( const QString& client, QMenu* menu, QString& title )
1479 SalomeApp_Module::contextMenuPopup(client, menu, title);
1482 getApp()->selectionMgr()->selectedObjects(lst);
1483 if (lst.Extent() < 1)
1486 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
1487 _PTR(Study) study = appStudy->studyDS();
1489 bool isImported = true;
1490 SALOME_ListIteratorOfListIO anIt (lst);
1491 for (; anIt.More() && isImported; anIt.Next()) {
1492 Handle(SALOME_InteractiveObject) io = anIt.Value();
1493 _PTR(SObject) aSObj = study->FindObjectID(io->getEntry());
1495 if (lst.Extent() == 1) {
1496 // Set context menu title
1497 if (client == "OCCViewer" || client == "VTKViewer")
1498 title = QString(aSObj->GetName().c_str());
1501 CORBA::Object_var anObj = GeometryGUI::ClientSObjectToObject(aSObj);
1502 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(anObj);
1503 if (CORBA::is_nil(aGeomObj) || aGeomObj->GetType() != GEOM_IMPORT)
1509 menu->addAction(action(5029)); // Reload imported shape
1513 void GeometryGUI::createPreferences()
1515 int tabId = addPreference( tr( "PREF_TAB_SETTINGS" ) );
1517 int genGroup = addPreference( tr( "PREF_GROUP_GENERAL" ), tabId );
1518 setPreferenceProperty( genGroup, "columns", 2 );
1520 int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), genGroup,
1521 LightApp_Preferences::Selector,
1522 "Geometry", "display_mode" );
1524 addPreference( tr( "PREF_SHADING_COLOR" ), genGroup,
1525 LightApp_Preferences::Color, "Geometry", "shading_color" );
1527 addPreference( tr( "PREF_WIREFRAME_COLOR" ), genGroup,
1528 LightApp_Preferences::Color, "Geometry", "wireframe_color" );
1530 addPreference( tr( "PREF_FREE_BOUND_COLOR" ), genGroup,
1531 LightApp_Preferences::Color, "Geometry", "free_bound_color" );
1533 addPreference( tr( "PREF_LINE_COLOR"), genGroup,
1534 LightApp_Preferences::Color, "Geometry", "line_color" );
1536 addPreference( tr( "PREF_POINT_COLOR"), genGroup,
1537 LightApp_Preferences::Color, "Geometry", "point_color" );
1539 addPreference( tr( "PREF_ISOS_COLOR" ), genGroup,
1540 LightApp_Preferences::Color, "Geometry", "isos_color" );
1542 int step = addPreference( tr( "PREF_STEP_VALUE" ), genGroup,
1543 LightApp_Preferences::IntSpin, "Geometry", "SettingsGeomStep" );
1545 int VertexGroup = addPreference( tr( "PREF_GROUP_VERTEX" ), tabId );
1546 setPreferenceProperty( VertexGroup, "columns", 2 );
1548 int typeOfMarker = addPreference( tr( "PREF_TYPE_OF_MARKER" ), VertexGroup,
1549 LightApp_Preferences::Selector, "Geometry", "type_of_marker" );
1551 int markerScale = addPreference( tr( "PREF_MARKER_SCALE" ), VertexGroup,
1552 LightApp_Preferences::DblSpin, "Geometry", "marker_scale" );
1554 // Set property for default display mode
1555 QStringList aModesList;
1556 aModesList.append( tr("MEN_WIREFRAME") );
1557 aModesList.append( tr("MEN_SHADING") );
1559 QList<QVariant> anIndexesList;
1560 anIndexesList.append(0);
1561 anIndexesList.append(1);
1563 setPreferenceProperty( dispmode, "strings", aModesList );
1564 setPreferenceProperty( dispmode, "indexes", anIndexesList );
1566 // Set property for step value for spinboxes
1567 setPreferenceProperty( step, "min", 1 );
1568 setPreferenceProperty( step, "max", 10000 );
1569 setPreferenceProperty( step, "precision", 3 );
1571 // Set property for type of vertex marker
1572 QStringList aTypeOfMarkerList;
1573 QList<QVariant> anTypeOfMarkerIndexesList;
1575 aTypeOfMarkerList.append( tr("TOM_PLUS") );
1576 anTypeOfMarkerIndexesList.append(Aspect_TOM_PLUS);
1578 aTypeOfMarkerList.append( tr("TOM_POINT") );
1579 anTypeOfMarkerIndexesList.append(Aspect_TOM_POINT);
1581 aTypeOfMarkerList.append( tr("TOM_STAR") );
1582 anTypeOfMarkerIndexesList.append(Aspect_TOM_STAR);
1584 aTypeOfMarkerList.append( tr("TOM_O") );
1585 anTypeOfMarkerIndexesList.append(Aspect_TOM_O);
1587 aTypeOfMarkerList.append( tr("TOM_X") );
1588 anTypeOfMarkerIndexesList.append(Aspect_TOM_X);
1590 aTypeOfMarkerList.append( tr("TOM_O_POINT") );
1591 anTypeOfMarkerIndexesList.append(Aspect_TOM_O_POINT);
1593 aTypeOfMarkerList.append( tr("TOM_O_PLUS") );
1594 anTypeOfMarkerIndexesList.append(Aspect_TOM_O_PLUS);
1596 aTypeOfMarkerList.append( tr("TOM_O_STAR") );
1597 anTypeOfMarkerIndexesList.append(Aspect_TOM_O_STAR);
1599 aTypeOfMarkerList.append( tr("TOM_O_X") );
1600 anTypeOfMarkerIndexesList.append(Aspect_TOM_O_X);
1603 setPreferenceProperty( typeOfMarker, "strings", aTypeOfMarkerList );
1604 setPreferenceProperty( typeOfMarker, "indexes", anTypeOfMarkerIndexesList );
1606 // Set property for Vertex Marker scale
1607 setPreferenceProperty( markerScale, "min", 1. );
1608 setPreferenceProperty( markerScale, "max", 7. );
1609 setPreferenceProperty( markerScale, "precision", 0.01 );
1610 setPreferenceProperty( markerScale, "step", 0.5 );
1614 void GeometryGUI::preferencesChanged( const QString& section, const QString& param )
1616 if (section == "Geometry") {
1617 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
1618 if (param == QString("SettingsGeomStep")) {
1619 double spin_step = aResourceMgr->doubleValue(section, param, 100.);
1620 EmitSignalDefaultStepValueChanged(spin_step);
1625 LightApp_Displayer* GeometryGUI::displayer()
1628 myDisplayer = new GEOM_Displayer( dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) );
1632 void GeometryGUI::setLocalSelectionMode(const int mode)
1634 myLocalSelectionMode = mode;
1636 int GeometryGUI::getLocalSelectionMode() const
1638 return myLocalSelectionMode;
1641 const char gSeparator = '_'; // character used to separate parameter names
1642 const char gDigitsSep = ':'; // character used to separate numeric parameter values (color = r:g:b)
1645 * \brief Store visual parameters
1647 * This method is called just before the study document is saved.
1648 * Store visual parameters in AttributeParameter attribue(s)
1650 void GeometryGUI::storeVisualParameters (int savePoint)
1652 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
1653 if (!appStudy || !appStudy->studyDS())
1655 _PTR(Study) studyDS = appStudy->studyDS();
1657 // componentName is used for encoding of entries when storing them in IParameters
1658 std::string componentName = myComponentGeom->ComponentDataType();
1659 //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
1660 //if (!aSComponent) return;
1663 _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
1664 componentName.c_str(),
1666 _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
1668 // viewers counters are used for storing view_numbers in IParameters
1669 int vtkViewers(0), occViewers(0);
1671 QList<SUIT_ViewManager*> lst;
1672 QList<SUIT_ViewManager*>::Iterator it;
1674 // main cycle to store parameters of displayed objects
1676 vtkViewers = occViewers = 0;
1677 getApp()->viewManagers(lst);
1678 for (it = lst.begin(); it != lst.end(); it++)
1680 SUIT_ViewManager* vman = *it;
1681 QString vType = vman->getType();
1683 // saving VTK actors properties
1684 if (vType == SVTK_Viewer::Type())
1686 QVector<SUIT_ViewWindow*> views = vman->getViews();
1687 for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++)
1689 if (SVTK_ViewWindow* vtkView = dynamic_cast<SVTK_ViewWindow*>(views[i]))
1691 vtkActorCollection* allActors = vtkView->getRenderer()->GetActors();
1692 allActors->InitTraversal();
1693 while (vtkActor* actor = allActors->GetNextActor())
1695 if (actor->GetVisibility()) // store only visible actors
1697 GEOM_Actor* aGeomActor = 0;
1698 if (actor->IsA("GEOM_Actor"))
1699 aGeomActor = GEOM_Actor::SafeDownCast(actor);
1700 if (aGeomActor && aGeomActor->hasIO())
1702 Handle(SALOME_InteractiveObject) io = aGeomActor->getIO();
1705 // entry is "encoded" = it does NOT contain component adress, since it is a
1706 // subject to change on next component loading
1707 std::string entry = ip->encodeEntry(io->getEntry(), componentName);
1709 std::string param, occParam = vType.toLatin1().data();
1710 occParam += gSeparator;
1711 occParam += QString::number(vtkViewers).toLatin1().data();
1712 occParam += gSeparator;
1714 param = occParam + "Visibility";
1715 ip->setParameter(entry, param, "On");
1717 param = occParam + "DisplayMode";
1718 ip->setParameter(entry, param, QString::number
1719 (aGeomActor->getDisplayMode()).toLatin1().data());
1721 vtkFloatingPointType r, g, b;
1722 aGeomActor->GetColor(r, g, b);
1723 QString colorStr = QString::number(r);
1724 colorStr += gDigitsSep; colorStr += QString::number(g);
1725 colorStr += gDigitsSep; colorStr += QString::number(b);
1726 param = occParam + "Color";
1727 ip->setParameter(entry, param, colorStr.toLatin1().data());
1729 param = occParam + "Opacity";
1730 ip->setParameter(entry, param, QString::number(aGeomActor->GetOpacity()).toLatin1().data());
1732 int nbUIso(0), nbVIso(0);
1733 aGeomActor->GetNbIsos(nbUIso,nbVIso);
1734 QString isosStr = QString::number(nbUIso);
1735 isosStr += gDigitsSep;
1736 isosStr += QString::number(nbVIso);
1737 param = occParam + "Isos";
1738 ip->setParameter(entry, param, isosStr.toLatin1().data());
1739 } // if (io->hasEntry())
1740 } // GEOM_Actor && hasIO
1742 } // while.. actors traversal
1746 } // if (SVTK view model)
1747 else if (vType == SOCC_Viewer::Type()) // processing OCC viewers
1749 QVector<SUIT_ViewWindow*> views = vman->getViews();
1750 for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++)
1752 SOCC_ViewWindow* occView = dynamic_cast<SOCC_ViewWindow*>(views[i]);
1755 //Handle(AIS_InteractiveContext) ic =
1756 // ((OCCViewer_Viewer*)(occView->getViewManager()->getViewModel()))->getAISContext();
1757 OCCViewer_Viewer* viewModel = (OCCViewer_Viewer*)(vman->getViewModel());
1758 //OCCViewer_Viewer* viewModel = ((OCCViewer_ViewManager*)vman)->getOCCViewer();
1759 Handle(AIS_InteractiveContext) ic = viewModel->getAISContext();
1761 AIS_ListOfInteractive aList;
1762 ic->DisplayedObjects(aList);
1764 AIS_ListIteratorOfListOfInteractive ite (aList);
1765 for (; ite.More(); ite.Next())
1767 if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape)))
1769 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
1772 Handle(SALOME_InteractiveObject) io =
1773 Handle(SALOME_InteractiveObject)::DownCast(aSh->getIO());
1776 // entry is "encoded": it does NOT contain component adress,
1777 // since it is a subject to change on next component loading
1778 std::string entry = ip->encodeEntry(io->getEntry(), componentName);
1780 std::string param, occParam = vType.toLatin1().data();
1781 occParam += gSeparator;
1782 occParam += QString::number(occViewers).toLatin1().data();
1783 occParam += gSeparator;
1786 param = occParam + "Visibility";
1787 ip->setParameter(entry, param, "On");
1790 param = occParam + "DisplayMode";
1791 int dm = aSh->DisplayMode();
1792 ip->setParameter(entry, param, QString::number(dm).toLatin1().data());
1795 // is a property of GEOM_Object, it is stored by GEOM engine
1798 param = occParam + "Transparency";
1799 ip->setParameter(entry, param, QString::number(aSh->Transparency()).toLatin1().data());
1802 Handle(AIS_Drawer) aDrawer = aSh->Attributes();
1803 int nbUIso = aDrawer->UIsoAspect()->Number();
1804 int nbVIso = aDrawer->VIsoAspect()->Number();
1805 QString isosStr = QString::number(nbUIso);
1806 isosStr += gDigitsSep;
1807 isosStr += QString::number(nbVIso);
1808 param = occParam + "Isos";
1809 ip->setParameter(entry, param, isosStr.toLatin1().data());
1810 } // if (io->hasEntry())
1812 } // if (GEOM_AISShape)
1813 } // for (AIS_ListOfInteractive)
1817 } // if (SOCC view model)
1820 // unknown viewer type
1822 } // for (viewManagers)
1826 * \brief Restore visual parameters
1828 * This method is called after the study document is opened.
1829 * Restore visual parameters from AttributeParameter attribue(s)
1831 void GeometryGUI::restoreVisualParameters (int savePoint)
1833 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
1834 if (!appStudy || !appStudy->studyDS())
1836 _PTR(Study) studyDS = appStudy->studyDS();
1838 // componentName is used for encoding of entries when storing them in IParameters
1839 std::string componentName = myComponentGeom->ComponentDataType();
1840 //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
1841 //if (!aSComponent) return;
1844 _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
1845 componentName.c_str(),
1847 _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
1849 std::vector<std::string> entries = ip->getEntries();
1851 for (std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt)
1853 // entry is a normal entry - it should be "decoded" (setting base adress of component)
1854 QString entry (ip->decodeEntry(*entIt).c_str());
1856 // Check that the entry corresponds to a real object in the Study
1857 // as the object may be deleted or modified after the visual state is saved.
1858 _PTR(SObject) so = studyDS->FindObjectID(entry.toLatin1().data());
1859 if (!so) continue; //Skip the not existent entry
1861 std::vector<std::string> paramNames = ip->getAllParameterNames( *entIt );
1862 std::vector<std::string> paramValues = ip->getAllParameterValues( *entIt );
1864 std::vector<std::string>::iterator namesIt = paramNames.begin();
1865 std::vector<std::string>::iterator valuesIt = paramValues.begin();
1867 // actors are stored in a map after displaying of them for
1868 // quicker access in the future: map < viewID to actor >
1869 NCollection_DataMap<int, GEOM_Actor* > vtkActors;
1870 NCollection_DataMap<int, Handle(GEOM_AISShape)> occActors;
1872 for (; namesIt != paramNames.end(); ++namesIt, ++valuesIt)
1874 // visual parameters are stored in strings as follows: ViewerType_ViewIndex_ParamName.
1875 // '_' is used as separator and should not be used in viewer type or parameter names.
1876 QStringList lst = QString((*namesIt).c_str()).split(gSeparator, QString::SkipEmptyParts);
1877 if (lst.size() != 3)
1880 QString viewerTypStr = lst[0];
1881 QString viewIndexStr = lst[1];
1882 QString paramNameStr = lst[2];
1885 int viewIndex = viewIndexStr.toUInt(&ok);
1886 if (!ok) // bad conversion of view index to integer
1890 if (viewerTypStr == SVTK_Viewer::Type())
1892 GEOM_Actor* vActor = 0;
1893 if (vtkActors.IsBound(viewIndex))
1894 vActor = vtkActors.Find(viewIndex);
1896 if (paramNameStr == "Visibility")
1898 if (!vActor && displayer())
1900 QList<SUIT_ViewManager*> lst;
1901 getApp()->viewManagers(viewerTypStr, lst);
1903 // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
1904 if (viewIndex >= 0 && viewIndex < lst.count()) {
1905 SUIT_ViewManager* vman = lst.at(viewIndex);
1906 SUIT_ViewModel* vmodel = vman->getViewModel();
1907 // SVTK view model can be casted to SALOME_View
1908 displayer()->Display(entry, true, dynamic_cast<SALOME_View*>(vmodel));
1910 // store displayed actor in a temporary map for quicker
1911 // access later when restoring other parameters
1912 SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
1913 vtkRenderer* Renderer = vtkView->getRenderer();
1914 vtkActorCollection* theActors = Renderer->GetActors();
1915 theActors->InitTraversal();
1916 bool isFound = false;
1917 vtkActor *ac = theActors->GetNextActor();
1918 for (; ac != NULL && !isFound; ac = theActors->GetNextActor()) {
1919 if (ac->IsA("GEOM_Actor")) {
1920 GEOM_Actor* aGeomAc = GEOM_Actor::SafeDownCast(ac);
1921 if (aGeomAc->hasIO()) {
1922 Handle(SALOME_InteractiveObject) io =
1923 Handle(SALOME_InteractiveObject)::DownCast(aGeomAc->getIO());
1924 if (io->hasEntry() && strcmp(io->getEntry(), entry.toLatin1().data()) == 0) {
1926 vtkActors.Bind(viewIndex, aGeomAc);
1933 } // if (paramNameStr == "Visibility")
1936 // the rest properties "work" with GEOM_Actor
1939 QString val ((*valuesIt).c_str());
1941 if (paramNameStr == "DisplayMode") {
1942 vActor->setDisplayMode(val.toInt());
1944 else if (paramNameStr == "Color") {
1945 QStringList colors = val.split(gDigitsSep, QString::SkipEmptyParts);
1946 if (colors.count() == 3)
1947 vActor->SetColor(colors[0].toFloat(), colors[1].toFloat(), colors[2].toFloat());
1949 else if (paramNameStr == "Opacity") {
1950 vActor->SetOpacity(val.toFloat());
1952 else if (paramNameStr == "Isos") {
1953 QStringList isos = val.split(gDigitsSep, QString::SkipEmptyParts);
1954 if (isos.count() == 2) {
1955 int aIsos[2] = {isos[0].toInt(), isos[1].toInt()};
1956 vActor->SetNbIsos(aIsos);
1960 } // other parameters than Visibility
1962 else if (viewerTypStr == SOCC_Viewer::Type())
1964 //Handle(AIS_InteractiveObject) occActor;
1965 Handle(GEOM_AISShape) occActor;
1966 if (occActors.IsBound(viewIndex))
1967 occActor = occActors.Find(viewIndex);
1969 // ViewModel and InteractiveContext
1970 SOCC_Viewer* occVModel = 0;
1971 Handle(AIS_InteractiveContext) ic;
1973 QList<SUIT_ViewManager*> lst;
1974 getApp()->viewManagers(viewerTypStr, lst);
1976 // SOCC ViewManager always has 1 ViewWindow, so view index is index of view manager
1977 if (viewIndex >= 0 && viewIndex < lst.count()) {
1978 SUIT_ViewManager* vman = lst.at(viewIndex);
1979 SUIT_ViewModel* vmodel = vman->getViewModel();
1980 occVModel = dynamic_cast<SOCC_Viewer*>(vmodel);
1982 ic = occVModel->getAISContext();
1988 if (paramNameStr == "Visibility")
1990 if (occActor.IsNull() && displayer())
1992 displayer()->Display(entry, true, occVModel);
1994 // store displayed actor in a temporary map for quicker
1995 // access later when restoring other parameters
1996 AIS_ListOfInteractive aList;
1997 ic->DisplayedObjects(aList);
1998 bool isFound = false;
1999 AIS_ListIteratorOfListOfInteractive ite (aList);
2000 for (; ite.More() && !isFound; ite.Next()) {
2001 if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
2002 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
2004 Handle(SALOME_InteractiveObject) io =
2005 Handle(SALOME_InteractiveObject)::DownCast(aSh->getIO());
2006 if (io->hasEntry() && strcmp(io->getEntry(), entry.toLatin1().data()) == 0) {
2008 occActors.Bind(viewIndex, aSh);
2014 } // if (paramNameStr == "Visibility")
2017 // the rest properties "work" with GEOM_AISShape
2018 if (!occActor.IsNull())
2020 QString val ((*valuesIt).c_str());
2022 if (paramNameStr == "DisplayMode") {
2023 ic->SetDisplayMode(occActor, AIS_DisplayMode(val.toInt()), false);
2024 //ic->Redisplay(occActor, Standard_False, Standard_True);
2026 // Color is restored by the GEOM engine
2027 else if (paramNameStr == "Transparency") {
2028 ic->SetTransparency(occActor, val.toFloat(), false);
2029 ic->Redisplay(occActor, Standard_False, Standard_True);
2031 else if (paramNameStr == "Isos") {
2032 QStringList isos = val.split(gDigitsSep, QString::SkipEmptyParts);
2033 if (isos.count() == 2) {
2034 Handle(AIS_Drawer) aDrawer = occActor->Attributes();
2035 int nbUIso = isos[0].toInt();
2036 int nbVIso = isos[1].toInt();
2037 Handle(Prs3d_IsoAspect) uIsoAspect = aDrawer->UIsoAspect();
2038 Handle(Prs3d_IsoAspect) vIsoAspect = aDrawer->VIsoAspect();
2039 uIsoAspect->SetNumber(nbUIso);
2040 vIsoAspect->SetNumber(nbVIso);
2041 aDrawer->SetUIsoAspect(uIsoAspect);
2042 aDrawer->SetVIsoAspect(vIsoAspect);
2043 ic->SetLocalAttributes(occActor, aDrawer);
2044 ic->Redisplay(occActor);
2048 } // other parameters than Visibility
2052 // unknown viewer type
2054 } // for names/parameters iterator
2055 } // for entries iterator
2057 // update all VTK and OCC views
2058 QList<SUIT_ViewManager*> lst;
2059 getApp()->viewManagers(lst);
2060 for (QList<SUIT_ViewManager*>::Iterator it = lst.begin(); it != lst.end(); it++) {
2061 SUIT_ViewModel* vmodel = (*it)->getViewModel();
2064 if (vmodel->getType() == SVTK_Viewer::Type()) {
2065 SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) (*it)->getActiveView();
2066 vtkView->getRenderer()->ResetCameraClippingRange();
2069 else if (vmodel->getType() == SOCC_Viewer::Type()) {
2070 //SOCC_ViewWindow* occView = (SOCC_ViewWindow*) (*it)->getActiveView();
2071 SALOME_View* occVMod = dynamic_cast<SALOME_View*>(vmodel);
2078 void GeometryGUI::onViewAboutToShow()
2080 SUIT_ViewWindow* window = application()->desktop()->activeWindow();
2081 QAction* a = action( 218 );
2083 a->setEnabled(true);
2084 bool vmode = window->getCustomData("VectorsMode").toBool();
2085 a->setText ( vmode == 1 ? tr( "MEN_VECTOR_MODE_OFF" ) : tr("MEN_VECTOR_MODE_ON") );
2087 a->setText ( tr("MEN_VECTOR_MODE_ON") );
2088 a->setEnabled(false);