1 // VISU VISUGUI : GUI of VISU component
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : VisuGUI_Module.cxx
25 // Author : Laurent CORNABE
29 #include "VisuGUI_Module.h"
31 #include "QtxPopupMgr.h"
33 #include "SUIT_Study.h"
34 #include "SUIT_Desktop.h"
35 #include "SUIT_ResourceMgr.h"
36 #include "SUIT_Accel.h"
37 #include "SUIT_Session.h"
39 #include "CAM_Module.h"
41 #include "SALOME_Event.hxx"
42 #include "SalomeApp_Application.h"
43 #include "LightApp_SelectionMgr.h"
44 #include "LightApp_VTKSelector.h"
45 #include "LightApp_Preferences.h"
46 #include "LightApp_Displayer.h"
48 #include "SALOMEDSClient_ClientFactory.hxx"
49 #include "SALOMEDSClient_IParameters.hxx"
51 #include "VVTK_ViewManager.h"
52 #include "VVTK_ViewWindow.h"
53 #include "VVTK_ViewModel.h"
55 #include "SVTK_ViewModel.h"
56 #include "SVTK_ViewManager.h"
57 #include "SVTK_MainWindow.h"
58 #include "SVTK_RenderWindowInteractor.h"
59 #include "VISU_Event.h"
61 #include "VisuGUI_Prs3dTools.h"
62 #include "VisuGUI_ClippingDlg.h"
64 #include "VISU_GaussPoints_i.hh"
65 #include "VISU_GaussPtsAct.h"
66 #include "VisuGUI_GaussPointsDlg.h"
68 #include "VISU_Gen_i.hh"
69 #include "VISU_Result_i.hh"
70 #include "VISU_CutLines_i.hh"
72 #include "VISU_Actor.h"
73 #include "VISU_ScalarMapAct.h"
74 #include "VisuGUI_Tools.h"
75 #include "VisuGUI_ActionsDef.h"
77 #include "VISU_WidgetCtrl.hxx"
78 #include "VISU_PlanesWidget.hxx"
79 #include "VISU_SphereWidget.hxx"
81 #include "SalomeApp_Study.h"
82 #include "VVTK_MainWindow.h"
83 #include "VISU_View_i.hh"
87 #include <vtkRenderer.h>
88 #include <vtkCamera.h>
89 #include <vtkTimerLog.h>
95 static int MYDEBUG = 0;
97 static int MYDEBUG = 0;
100 #define SAVE_VISU_STATE 5090
102 #define GAUSS_NEW_VIEWER 5100
103 #define GAUSS_CREATE_PRS 5200
104 #define GAUSS_RENAME 5210
105 #define GAUSS_EDIT_PRS 5300
106 #define GAUSS_COPY_PRS 5310
107 #define GAUSS_ERASE_PRS 5400
108 #define GAUSS_DISPLAY_PRS 5500
109 #define GAUSS_DISPLAY_ONLY_PRS 5600
111 #define GAUSS_SAVE_CONFIGURATION 5700
112 #define GAUSS_OVERWRITE_CONFIGURATION 5701
113 #define GAUSS_RESTORE_CONFIGURATION 5702
114 #define GAUSS_RENAME_CONFIGURATION 5703
117 CreateCurves( SalomeApp_Module* theModule,
118 VISU::CutLines_i* thePrs,
120 const bool theCreate = true );
122 using namespace VISU;
126 //---------------------------------------------------------------
127 typedef void (SUIT_ViewWindow::* TViewVisibility)();
129 SetViewVisibility(SalomeApp_Application* app,
130 TViewVisibility theViewVisibility)
133 app->viewManagers( VVTK_Viewer::Type(), l );
134 ViewManagerList::const_iterator anIt = l.begin(), aLast = l.end();
135 for( ; anIt!=aLast; anIt++ )
136 if( SUIT_ViewManager* aViewManager = *anIt )
138 QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
139 int aSize = aViews.size();
140 for(int anId = 0; anId < aSize; anId++)
142 if(SUIT_ViewWindow* aView = aViews[anId])
143 (aView->* theViewVisibility)();
149 //---------------------------------------------------------------
157 //---------------------------------------------------------------
164 //---------------------------------------------------------------
167 initialize( CAM_Application* theApp )
169 VisuGUI::initialize( theApp );
171 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
173 // "Save VISU State" command is moved from SalomeApp_Applicaiton
174 createAction( SAVE_VISU_STATE, tr( "TOT_DESK_FILE_SAVE_GUI_STATE" ), QIconSet(),
175 tr( "MEN_DESK_FILE_SAVE_GUI_STATE" ), tr( "PRP_DESK_FILE_SAVE_GUI_STATE" ),
176 0, getApp()->desktop(), false, getApp(), SLOT( onSaveGUIState() ) );
177 int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
178 createMenu( SAVE_VISU_STATE, fileMenu, 9, -1 );
181 aPixmap = aResourceMgr->loadPixmap("VISU",tr("ICON_GAUSS_NEW_VIEWER"));
182 createAction( GAUSS_NEW_VIEWER,
183 tr("MEN_GAUSS_NEW_VIEWER"),
185 tr("MEN_GAUSS_NEW_VIEWER"),
186 tr("MEN_GAUSS_NEW_VIEWER"),
191 SLOT(onCreateViewManager()));
192 int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 );
193 int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
194 createMenu( action( GAUSS_NEW_VIEWER ), newWinMenu, -1 );
196 // Add actions to menus
197 createMenu( tr( "MEN_GAUSS" ), -1, -1, 30 );
198 //createMenu( GAUSS_CREATE_PRS, aMenuId, 10 );
200 QString aViewerType = VVTK_Viewer::Type();
201 SUIT_Accel* accel = getApp()->accel();
202 accel->setActionKey( SUIT_Accel::PanLeft, Key_Left, aViewerType );
203 accel->setActionKey( SUIT_Accel::PanRight, Key_Right, aViewerType );
204 accel->setActionKey( SUIT_Accel::PanUp, Key_Up, aViewerType );
205 accel->setActionKey( SUIT_Accel::PanDown, Key_Down, aViewerType );
206 accel->setActionKey( SUIT_Accel::ZoomIn, Key_PageUp, aViewerType );
207 accel->setActionKey( SUIT_Accel::ZoomOut, Key_PageDown, aViewerType );
208 accel->setActionKey( SUIT_Accel::RotateLeft, CTRL+Key_Left, aViewerType );
209 accel->setActionKey( SUIT_Accel::RotateRight, CTRL+Key_Right, aViewerType );
210 accel->setActionKey( SUIT_Accel::RotateUp, CTRL+Key_Up, aViewerType );
211 accel->setActionKey( SUIT_Accel::RotateDown, CTRL+Key_Down, aViewerType );
212 accel->setActionKey( SVTK::PlusSpeedIncrementEvent, Key_Plus, aViewerType );
213 accel->setActionKey( SVTK::MinusSpeedIncrementEvent, Key_Minus, aViewerType );
215 connect( getApp(), SIGNAL( viewManagerAdded( SUIT_ViewManager* ) ),
216 this, SLOT( OnViewManagerAdded (SUIT_ViewManager*) ) );
218 // Prepare popup menus
219 QtxPopupMgr* mgr = popupMgr();
222 aPixmap = aResourceMgr->loadPixmap( "VISU", tr( "ICON_GAUSS_POINTS" ) );
223 createAction( GAUSS_CREATE_PRS, tr("MEN_GAUSS_CREATE_PRS"), aPixmap,
224 tr("MEN_GAUSS_CREATE_PRS"), "", 0, this, false,
225 this, SLOT(OnCreateGaussPoints()));
226 mgr->insert( action( GAUSS_CREATE_PRS ), -1, 0, -1 );
227 mgr->setRule( action( GAUSS_CREATE_PRS ),
228 "client='ObjectBrowser' and selcount=1 "
229 "and type='VISU::TTIMESTAMP' "
230 "and $medEntity in {'EDGE_ENTITY' 'FACE_ENTITY' 'CELL_ENTITY'} "
231 "and $medSource in {'eImportFile' 'eCopyAndImportFile'} ",
234 createMenu( action( GAUSS_CREATE_PRS ), createMenu( tr( "MEN_VISUALISATION" ), -1 ), -1 );
235 createTool( GAUSS_CREATE_PRS, createTool( tr( "TOOL_VISUALISATION" ) ), -1 );
237 createAction( GAUSS_RENAME, VisuGUI::tr("MEN_RENAME"), QIconSet(),
238 VisuGUI::tr("MEN_RENAME"), "", 0, this, false,
239 this, SLOT(OnRename()));
240 mgr->insert( action( GAUSS_RENAME ), -1, 0, -1 );
241 mgr->setRule( action( GAUSS_RENAME ),
242 "selcount=1 and type='VISU::TGAUSSPOINTS'",
245 createAction( GAUSS_EDIT_PRS, VisuGUI::tr("MEN_EDIT_PRS"), QIconSet(),
246 VisuGUI::tr("MEN_EDIT_PRS"), "", 0, this, false,
247 this, SLOT(OnEditGaussPoints()));
248 mgr->insert( action( GAUSS_EDIT_PRS ), -1, 0, -1 );
249 mgr->setRule( action( GAUSS_EDIT_PRS ),
250 "selcount=1 and type='VISU::TGAUSSPOINTS'",
253 createAction( GAUSS_COPY_PRS, VisuGUI::tr("MEN_COPY_PRS"), QIconSet(),
254 VisuGUI::tr("MEN_COPY_PRS"), "", 0, this, false,
255 this, SLOT(OnCopyPresentation()));
256 mgr->insert( action( GAUSS_COPY_PRS ), -1, 0, -1 );
257 mgr->setRule( action( GAUSS_COPY_PRS ),
258 "selcount=1 and type='VISU::TGAUSSPOINTS'",
260 action( GAUSS_COPY_PRS )->setEnabled(false);
262 aRule = "(selcount>0 and type='VISU::TGAUSSPOINTS')";
264 createAction( GAUSS_ERASE_PRS, VisuGUI::tr("MEN_ERASE"), QIconSet(),
265 VisuGUI::tr("MEN_ERASE"), "", 0, this, false,
266 this, SLOT(OnErasePrs()));
267 mgr->insert( action( GAUSS_ERASE_PRS ), -1, -1, -1 ); // erase
268 mgr->setRule( action( GAUSS_ERASE_PRS ),
269 aRule + " and ({true} in $canBeDisplayed) and (isVisible=true)", true );
271 createAction( GAUSS_DISPLAY_PRS, VisuGUI::tr("MEN_DISPLAY"), QIconSet(),
272 VisuGUI::tr("MEN_DISPLAY"), "", 0, this, false,
273 this, SLOT(OnDisplayPrs()));
274 mgr->insert( action( GAUSS_DISPLAY_PRS ), -1, -1, -1 ); // display
275 mgr->setRule( action( GAUSS_DISPLAY_PRS ),
276 aRule + " and ({true} in $canBeDisplayed) and (isVisible=false)", true );
278 createAction( GAUSS_DISPLAY_ONLY_PRS, VisuGUI::tr("MEN_DISPLAY_ONLY"), QIconSet(),
279 VisuGUI::tr("MEN_DISPLAY_ONLY"), "", 0, this, false,
280 this, SLOT(OnDisplayOnlyPrs()));
281 mgr->insert( action( GAUSS_DISPLAY_ONLY_PRS ), -1, -1, -1 ); // display only
282 mgr->setRule( action( GAUSS_DISPLAY_ONLY_PRS ),
283 aRule + " and ({true} in $canBeDisplayed)", true );
285 createAction( GAUSS_RENAME_CONFIGURATION, VisuGUI::tr("MEN_RENAME"), QIconSet(),
286 VisuGUI::tr("MEN_RENAME"), "", 0, this, false,
287 this, SLOT(OnRename()));
288 mgr->insert( action( GAUSS_RENAME_CONFIGURATION ), -1, -1, -1 );
289 mgr->setRule( action( GAUSS_RENAME_CONFIGURATION ), "selcount=1 and type='VISU::TGAUSSVIEW'", true );
291 createAction( GAUSS_SAVE_CONFIGURATION, tr("MEN_SAVE_CONFIGURATION"), QIconSet(),
292 tr("MEN_SAVE_CONFIGURATION"), "", 0, this, false,
293 this, SLOT(OnSaveConfiguration()));
294 mgr->insert( action( GAUSS_SAVE_CONFIGURATION ), -1, -1, -1 );
295 mgr->setRule( action( GAUSS_SAVE_CONFIGURATION ),
296 "selcount>=0 and client='VVTK' and activeView='VVTK'", true );
298 createAction( GAUSS_OVERWRITE_CONFIGURATION, tr("MEN_OVERWRITE_CONFIGURATION"), QIconSet(),
299 tr("MEN_OVERWRITE_CONFIGURATION"), "", 0, this, false,
300 this, SLOT(OnOverwriteConfiguration()));
301 mgr->insert( action( GAUSS_OVERWRITE_CONFIGURATION ), -1, -1, -1 );
302 mgr->setRule( action( GAUSS_OVERWRITE_CONFIGURATION ),
303 "selcount>0 and type='VISU::TGAUSSVIEW' and activeView='VVTK'", true );
305 createAction( GAUSS_RESTORE_CONFIGURATION, tr("MEN_RESTORE_CONFIGURATION"), QIconSet(),
306 tr("MEN_RESTORE_CONFIGURATION"), "", 0, this, false,
307 this, SLOT(OnRestoreConfiguration()));
308 mgr->insert( action( GAUSS_RESTORE_CONFIGURATION ), -1, -1, -1 );
309 mgr->setRule( action( GAUSS_RESTORE_CONFIGURATION ),
310 "selcount=1 and type='VISU::TGAUSSVIEW'", true );
313 //---------------------------------------------------------------
316 activateModule( SUIT_Study* theStudy )
318 VisuGUI::activateModule( theStudy );
320 SetViewVisibility(getApp(),&SUIT_ViewWindow::show);
326 //---------------------------------------------------------------
329 deactivateModule( SUIT_Study* theStudy )
331 VisuGUI::deactivateModule( theStudy );
333 SetViewVisibility(getApp(),&SUIT_ViewWindow::hide);
339 //---------------------------------------------------------------
342 onCreateViewManager()
344 SalomeApp_Application* anApp = getApp();
345 SUIT_ResourceMgr* aResourceMgr = anApp->resourceMgr();
346 VVTK_ViewManager* aViewManager = new VVTK_ViewManager( anApp->activeStudy(), anApp->desktop() );
347 VVTK_Viewer* aViewer = (VVTK_Viewer*)aViewManager->getViewModel();
348 aViewer->setBackgroundColor( aResourceMgr->colorValue( "VTKViewer", "background", aViewer->backgroundColor() ) );
349 aViewer->setTrihedronSize( aResourceMgr->integerValue( "VTKViewer", "trihedron_size", aViewer->trihedronSize() ),
350 aResourceMgr->booleanValue( "VTKViewer", "relative_size", aViewer->trihedronRelative() ) );
351 new LightApp_VTKSelector( aViewer, anApp->selectionMgr() );
352 anApp->addViewManager( aViewManager );
354 aViewManager->createViewWindow();
356 return aViewer->getViewManager();
360 //---------------------------------------------------------------
365 VisuGUI::createPreferences();
367 createGaussPointsPreferences();
368 createInsideCursorPreferences();
369 createOutsideCursorPreferences();
370 createPickingPreferences();
371 createSpaceMousePreferences();
372 createRecorderPreferences();
376 //---------------------------------------------------------------
379 createGaussPointsPreferences()
381 int gaussTab = addPreference( tr( "VISU_GAUSS_PREF_TAB_TTL" ) );
382 int primitiveGr = addPreference( tr( "VISU_GAUSS_PREF_PRIMITIVE_GROUP_TTL" ), gaussTab );
383 setPreferenceProperty( primitiveGr, "columns", 1 );
385 int primitiveTypePref = addPreference( tr( "VISU_GAUSS_PREF_PRIMITIVE_TYPE" ), primitiveGr,
386 LightApp_Preferences::Selector, "VISU",
387 "point_sprite_primitive_type" );
390 values.append( tr( "VISU_GAUSS_PREF_POINTSPRITE" ) );
391 values.append( tr( "VISU_GAUSS_PREF_OPENGLPOINT" ) );
392 values.append( tr( "VISU_GAUSS_PREF_GEOMSPHERE" ) );
393 QValueList<QVariant> indices;
397 setPreferenceProperty( primitiveTypePref, "strings", values );
398 setPreferenceProperty( primitiveTypePref, "indexes", indices );
400 int clampPref = addPreference( tr( "VISU_GAUSS_PREF_CLAMP" ), primitiveGr,
401 LightApp_Preferences::IntSpin, "VISU", "point_sprite_clamp" );
402 setPreferenceProperty( clampPref, "min", 1 );
403 setPreferenceProperty( clampPref, "max", 512 );
405 addPreference( tr( "VISU_GAUSS_PREF_MAIN_TEXTURE" ), primitiveGr,
406 LightApp_Preferences::File, "VISU", "point_sprite_main_texture" );
408 addPreference( tr( "VISU_GAUSS_PREF_ALPHA_TEXTURE" ), primitiveGr,
409 LightApp_Preferences::File, "VISU", "point_sprite_alpha_texture" );
411 int alphaThresholdPref = addPreference( tr( "VISU_GAUSS_PREF_ALPHA_THRESHOLD" ), primitiveGr,
412 LightApp_Preferences::DblSpin, "VISU",
413 "point_sprite_alpha_threshold" );
414 setPreferenceProperty( alphaThresholdPref, "min", 0.0 );
415 setPreferenceProperty( alphaThresholdPref, "max", 1.0 );
416 setPreferenceProperty( alphaThresholdPref, "step", 0.1 );
418 int resolutionPref = addPreference( tr( "VISU_GAUSS_PREF_RESOLUTION" ), primitiveGr,
419 LightApp_Preferences::IntSpin, "VISU", "geom_sphere_resolution" );
420 setPreferenceProperty( resolutionPref, "min", 3 );
421 setPreferenceProperty( resolutionPref, "max", 100 );
423 int faceLimitPref = addPreference( tr( "VISU_GAUSS_PREF_FACE_LIMIT" ), primitiveGr,
424 LightApp_Preferences::IntSpin, "VISU", "geom_sphere_face_limit" );
425 setPreferenceProperty( faceLimitPref, "min", 10 );
426 setPreferenceProperty( faceLimitPref, "max", 1000000 );
428 int sizeGr = addPreference( tr( "VISU_GAUSS_PREF_SIZE_GROUP_TTL" ), gaussTab );
429 setPreferenceProperty( sizeGr, "columns", 2 );
431 int minSizePref = addPreference( tr( "VISU_GAUSS_PREF_MIN_SIZE" ), sizeGr,
432 LightApp_Preferences::IntSpin, "VISU", "point_sprite_min_size" );
433 setPreferenceProperty( minSizePref, "min", 1 );
434 setPreferenceProperty( minSizePref, "max", 100 );
436 int maxSizePref = addPreference( tr( "VISU_GAUSS_PREF_MAX_SIZE" ), sizeGr,
437 LightApp_Preferences::IntSpin, "VISU", "point_sprite_max_size" );
438 setPreferenceProperty( maxSizePref, "min", 1 );
439 setPreferenceProperty( maxSizePref, "max", 100 );
441 int magnificationPref = addPreference( tr( "VISU_GAUSS_PREF_MAGNIFICATION" ), sizeGr,
442 LightApp_Preferences::IntSpin, "VISU",
443 "point_sprite_magnification" );
444 setPreferenceProperty( magnificationPref, "min", 10 );
445 setPreferenceProperty( magnificationPref, "max", 1000 );
447 int incrementPref = addPreference( tr( "VISU_GAUSS_PREF_INCREMENT" ), sizeGr,
448 LightApp_Preferences::DblSpin, "VISU", "point_sprite_increment" );
449 setPreferenceProperty( incrementPref, "min", 0.01 );
450 setPreferenceProperty( incrementPref, "max", 10 );
451 setPreferenceProperty( incrementPref, "step", 0.1 );
453 int geomGr = addPreference( tr( "VISU_GAUSS_PREF_GEOM_GROUP_TTL" ), gaussTab );
454 setPreferenceProperty( geomGr, "columns", 1 );
456 int sizePref = addPreference( tr( "VISU_GAUSS_PREF_SIZE" ), geomGr,
457 LightApp_Preferences::IntSpin, "VISU", "point_sprite_size" );
458 setPreferenceProperty( sizePref, "min", 1 );
459 setPreferenceProperty( sizePref, "max", 100 );
461 addPreference( tr( "VISU_GAUSS_PREF_COLOR" ), geomGr,
462 LightApp_Preferences::Color, "VISU", "point_sprite_color" );
464 // ScalarBar Preferences
465 int scalarBarGr = addPreference( tr( "VISU_GAUSS_SCALAR_BAR_PREF_GROUP_TTL" ), gaussTab );
466 setPreferenceProperty( scalarBarGr, "columns", 1 );
468 int activeBarPref = addPreference( tr( "VISU_GAUSS_PREF_ACTIVE_BAR" ), scalarBarGr,
469 LightApp_Preferences::Selector, "VISU", "scalar_bar_active_local" );
472 values.append( tr( "VISU_GAUSS_PREF_LOCAL" ) );
473 values.append( tr( "VISU_GAUSS_PREF_GLOBAL" ) );
477 setPreferenceProperty( activeBarPref, "strings", values );
478 setPreferenceProperty( activeBarPref, "indexes", indices );
480 addPreference( tr( "VISU_GAUSS_PREF_DISPLAY_GLOBAL" ), scalarBarGr,
481 LightApp_Preferences::Bool, "VISU", "scalar_bar_display_global" );
483 int colorPref = addPreference( tr( "VISU_GAUSS_PREF_SCALAR_BAR_MODE" ), scalarBarGr,
484 LightApp_Preferences::Selector, "VISU", "scalar_bar_bicolor" );
487 values.append( tr( "VISU_GAUSS_PREF_BICOLOR" ) );
488 values.append( tr( "VISU_GAUSS_PREF_RAINBOW" ) );
492 setPreferenceProperty( colorPref, "strings", values );
493 setPreferenceProperty( colorPref, "indexes", indices );
495 int spacingPref = addPreference( tr( "VISU_GAUSS_PREF_SPACING" ), scalarBarGr,
496 LightApp_Preferences::DblSpin, "VISU", "scalar_bar_spacing" );
497 setPreferenceProperty( spacingPref, "min", 0.01 );
498 setPreferenceProperty( spacingPref, "max", 1.0 );
499 setPreferenceProperty( spacingPref, "step", 0.01 );
503 //---------------------------------------------------------------
506 createInsideCursorPreferences()
508 int insideCursorTab = addPreference( tr( "VISU_GAUSS_INSIDE_CURSOR_PREF_TAB_TTL" ) );
510 int primitiveGr = addPreference( tr( "VISU_GAUSS_PREF_PRIMITIVE_GROUP_TTL" ), insideCursorTab );
511 setPreferenceProperty( primitiveGr, "columns", 1 );
513 int primitiveTypePref = addPreference( tr( "VISU_GAUSS_PREF_PRIMITIVE_TYPE" ), primitiveGr,
514 LightApp_Preferences::Selector, "VISU",
515 "inside_point_sprite_primitive_type" );
518 values.append( tr( "VISU_GAUSS_PREF_POINTSPRITE" ) );
519 values.append( tr( "VISU_GAUSS_PREF_OPENGLPOINT" ) );
520 values.append( tr( "VISU_GAUSS_PREF_GEOMSPHERE" ) );
521 QValueList<QVariant> indices;
525 setPreferenceProperty( primitiveTypePref, "strings", values );
526 setPreferenceProperty( primitiveTypePref, "indexes", indices );
528 int clampPref = addPreference( tr( "VISU_GAUSS_PREF_CLAMP" ), primitiveGr,
529 LightApp_Preferences::IntSpin, "VISU", "inside_point_sprite_clamp" );
530 setPreferenceProperty( clampPref, "min", 1 );
531 setPreferenceProperty( clampPref, "max", 512 );
533 addPreference( tr( "VISU_GAUSS_PREF_MAIN_TEXTURE" ), primitiveGr,
534 LightApp_Preferences::File, "VISU", "inside_point_sprite_main_texture" );
536 addPreference( tr( "VISU_GAUSS_PREF_ALPHA_TEXTURE" ), primitiveGr,
537 LightApp_Preferences::File, "VISU", "inside_point_sprite_alpha_texture" );
539 int alphaThresholdPref = addPreference( tr( "VISU_GAUSS_PREF_ALPHA_THRESHOLD" ), primitiveGr,
540 LightApp_Preferences::DblSpin, "VISU",
541 "inside_point_sprite_alpha_threshold" );
542 setPreferenceProperty( alphaThresholdPref, "min", 0.0 );
543 setPreferenceProperty( alphaThresholdPref, "max", 1.0 );
544 setPreferenceProperty( alphaThresholdPref, "step", 0.1 );
546 int resolutionPref = addPreference( tr( "VISU_GAUSS_PREF_RESOLUTION" ), primitiveGr,
547 LightApp_Preferences::IntSpin, "VISU",
548 "inside_geom_sphere_resolution" );
549 setPreferenceProperty( resolutionPref, "min", 3 );
550 setPreferenceProperty( resolutionPref, "max", 100 );
552 int faceLimitPref = addPreference( tr( "VISU_GAUSS_PREF_FACE_LIMIT" ), primitiveGr,
553 LightApp_Preferences::IntSpin, "VISU",
554 "inside_geom_sphere_face_limit" );
555 setPreferenceProperty( faceLimitPref, "min", 10 );
556 setPreferenceProperty( faceLimitPref, "max", 1000000 );
558 int sizeGr = addPreference( tr( "VISU_GAUSS_PREF_SIZE_GROUP_TTL" ), insideCursorTab );
559 setPreferenceProperty( sizeGr, "columns", 2 );
561 int minSizePref = addPreference( tr( "VISU_GAUSS_PREF_MIN_SIZE" ), sizeGr,
562 LightApp_Preferences::IntSpin, "VISU",
563 "inside_point_sprite_min_size" );
564 setPreferenceProperty( minSizePref, "min", 1 );
565 setPreferenceProperty( minSizePref, "max", 100 );
567 int maxSizePref = addPreference( tr( "VISU_GAUSS_PREF_MAX_SIZE" ), sizeGr,
568 LightApp_Preferences::IntSpin, "VISU",
569 "inside_point_sprite_max_size" );
570 setPreferenceProperty( maxSizePref, "min", 1 );
571 setPreferenceProperty( maxSizePref, "max", 100 );
573 int magnificationGr = addPreference( tr( "VISU_GAUSS_PREF_MAGNIFICATION_GROUP_TTL" ), insideCursorTab );
574 setPreferenceProperty( magnificationGr, "columns", 2 );
576 int magnificationPref = addPreference( tr( "VISU_GAUSS_PREF_MAGNIFICATION" ), magnificationGr,
577 LightApp_Preferences::IntSpin, "VISU",
578 "inside_point_sprite_magnification" );
579 setPreferenceProperty( magnificationPref, "min", 10 );
580 setPreferenceProperty( magnificationPref, "max", 1000 );
582 int incrementPref = addPreference( tr( "VISU_GAUSS_PREF_INCREMENT" ), magnificationGr,
583 LightApp_Preferences::DblSpin, "VISU",
584 "inside_point_sprite_increment" );
585 setPreferenceProperty( incrementPref, "min", 0.01 );
586 setPreferenceProperty( incrementPref, "max", 10 );
587 setPreferenceProperty( incrementPref, "step", 0.1 );
591 //---------------------------------------------------------------
594 createOutsideCursorPreferences()
596 int outsideCursorTab = addPreference( tr( "VISU_GAUSS_OUTSIDE_CURSOR_PREF_TAB_TTL" ) );
598 int primitiveGr = addPreference( tr( "VISU_GAUSS_PREF_PRIMITIVE_GROUP_TTL" ), outsideCursorTab );
599 setPreferenceProperty( primitiveGr, "columns", 1 );
601 int primitiveTypePref = addPreference( tr( "VISU_GAUSS_PREF_PRIMITIVE_TYPE" ), primitiveGr,
602 LightApp_Preferences::Selector, "VISU",
603 "outside_point_sprite_primitive_type" );
606 values.append( tr( "VISU_GAUSS_PREF_POINTSPRITE" ) );
607 values.append( tr( "VISU_GAUSS_PREF_OPENGLPOINT" ) );
608 values.append( tr( "VISU_GAUSS_PREF_GEOMSPHERE" ) );
609 QValueList<QVariant> indices;
613 setPreferenceProperty( primitiveTypePref, "strings", values );
614 setPreferenceProperty( primitiveTypePref, "indexes", indices );
616 int clampPref = addPreference( tr( "VISU_GAUSS_PREF_CLAMP" ), primitiveGr,
617 LightApp_Preferences::IntSpin, "VISU", "outside_point_sprite_clamp" );
618 setPreferenceProperty( clampPref, "min", 1 );
619 setPreferenceProperty( clampPref, "max", 512 );
621 addPreference( tr( "VISU_GAUSS_PREF_MAIN_TEXTURE" ), primitiveGr,
622 LightApp_Preferences::File, "VISU", "outside_point_sprite_main_texture" );
624 addPreference( tr( "VISU_GAUSS_PREF_ALPHA_TEXTURE" ), primitiveGr,
625 LightApp_Preferences::File, "VISU", "outside_point_sprite_alpha_texture" );
627 int alphaThresholdPref = addPreference( tr( "VISU_GAUSS_PREF_ALPHA_THRESHOLD" ), primitiveGr,
628 LightApp_Preferences::DblSpin, "VISU",
629 "outside_point_sprite_alpha_threshold" );
630 setPreferenceProperty( alphaThresholdPref, "min", 0.0 );
631 setPreferenceProperty( alphaThresholdPref, "max", 1.0 );
632 setPreferenceProperty( alphaThresholdPref, "step", 0.1 );
634 int resolutionPref = addPreference( tr( "VISU_GAUSS_PREF_RESOLUTION" ), primitiveGr,
635 LightApp_Preferences::IntSpin, "VISU",
636 "outside_geom_sphere_resolution" );
637 setPreferenceProperty( resolutionPref, "min", 3 );
638 setPreferenceProperty( resolutionPref, "max", 100 );
640 int faceLimitPref = addPreference( tr( "VISU_GAUSS_PREF_FACE_LIMIT" ), primitiveGr,
641 LightApp_Preferences::IntSpin, "VISU",
642 "outside_geom_sphere_face_limit" );
643 setPreferenceProperty( faceLimitPref, "min", 10 );
644 setPreferenceProperty( faceLimitPref, "max", 1000000 );
646 int sizeGr = addPreference( tr( "VISU_GAUSS_PREF_SIZE_GROUP_TTL" ), outsideCursorTab );
648 int sizePref = addPreference( tr( "VISU_GAUSS_PREF_SIZE" ), sizeGr,
649 LightApp_Preferences::IntSpin, "VISU", "outside_point_sprite_size" );
650 setPreferenceProperty( sizePref, "min", 1 );
651 setPreferenceProperty( sizePref, "max", 100 );
653 int colorGr = addPreference( tr( "VISU_GAUSS_PREF_COLOR_GROUP_TTL" ), outsideCursorTab );
654 setPreferenceProperty( colorGr, "columns", 1 );
656 addPreference( tr( "VISU_GAUSS_PREF_UNIFORM_COLOR" ), colorGr,
657 LightApp_Preferences::Bool, "VISU", "outside_point_sprite_uniform" );
659 addPreference( tr( "VISU_GAUSS_PREF_COLOR" ), colorGr,
660 LightApp_Preferences::Color, "VISU", "outside_point_sprite_color" );
664 //---------------------------------------------------------------
667 createPickingPreferences()
669 int pickingTab = addPreference( tr( "VISU_PICKING_PREF_TAB_TTL" ) );
672 int cursorGr = addPreference( tr( "VISU_PICKING_PREF_CURSOR_GROUP_TTL" ), pickingTab );
673 setPreferenceProperty( cursorGr, "columns", 1 );
675 int cursorSizePref = addPreference( tr( "VISU_PICKING_PREF_CURSOR_SIZE" ), cursorGr,
676 LightApp_Preferences::DblSpin, "VISU", "picking_cursor_size" );
677 setPreferenceProperty( cursorSizePref, "min", 0 );
678 setPreferenceProperty( cursorSizePref, "max", 1.0 );
679 setPreferenceProperty( cursorSizePref, "step", 0.1 );
681 int pyramidHeightPref = addPreference( tr( "VISU_PICKING_PREF_PYRAMID_HEIGHT" ), cursorGr,
682 LightApp_Preferences::DblSpin, "VISU", "picking_pyramid_height" );
683 setPreferenceProperty( pyramidHeightPref, "min", 1 );
684 setPreferenceProperty( pyramidHeightPref, "max", 100 );
686 /*int selectionColorPref = */
687 addPreference( tr( "VISU_PICKING_PREF_SELECTION_COLOR" ), cursorGr,
688 LightApp_Preferences::Color, "VISU", "picking_selection_color" );
691 int toleranceGr = addPreference( tr( "VISU_PICKING_PREF_TOLERANCE_GROUP_TTL" ), pickingTab );
693 int pointTolerancePref = addPreference( tr( "VISU_PICKING_PREF_POINT_SELECTION_TOLERANCE" ), toleranceGr,
694 LightApp_Preferences::DblSpin, "VISU", "picking_point_tolerance" );
695 setPreferenceProperty( pointTolerancePref, "min", 0.001 );
696 setPreferenceProperty( pointTolerancePref, "max", 10 );
697 setPreferenceProperty( pointTolerancePref, "step", 0.01 );
700 int infoWindowGr = addPreference( tr( "VISU_PICKING_PREF_INFO_WINDOW_GROUP_TTL" ), pickingTab );
701 setPreferenceProperty( infoWindowGr, "columns", 1 );
703 int transparencyPref = addPreference( tr( "VISU_PICKING_PREF_TRANSPARENCY" ), infoWindowGr,
704 LightApp_Preferences::IntSpin, "VISU", "picking_transparency" );
705 setPreferenceProperty( transparencyPref, "min", 0 );
706 setPreferenceProperty( transparencyPref, "max", 100 );
707 setPreferenceProperty( transparencyPref, "step", 10 );
709 int positionPref = addPreference( tr( "VISU_PICKING_PREF_POSITION" ), infoWindowGr,
710 LightApp_Preferences::Selector, "VISU", "picking_position" );
712 values.append( tr( "VISU_PICKING_PREF_BELOW_POINT" ) );
713 values.append( tr( "VISU_PICKING_PREF_TOP_LEFT_CORNER" ) );
714 QValueList<QVariant> indices;
717 setPreferenceProperty( positionPref, "strings", values );
718 setPreferenceProperty( positionPref, "indexes", indices );
721 int cameraGr = addPreference( tr( "VISU_PICKING_PREF_CAMERA_GROUP_TTL" ), pickingTab );
722 setPreferenceProperty( cameraGr, "columns", 1 );
724 int zoomFactorPref = addPreference( tr( "VISU_PICKING_PREF_ZOOM_FACTOR" ), cameraGr,
725 LightApp_Preferences::DblSpin, "VISU", "picking_zoom_factor" );
726 setPreferenceProperty( zoomFactorPref, "min", 0.1 );
727 setPreferenceProperty( zoomFactorPref, "max", 10.0 );
728 setPreferenceProperty( zoomFactorPref, "step", 0.1 );
730 int stepNumberPref = addPreference( tr( "VISU_PICKING_PREF_STEP_NUMBER" ), cameraGr,
731 LightApp_Preferences::IntSpin, "VISU", "picking_step_number" );
732 setPreferenceProperty( stepNumberPref, "min", 1 );
733 setPreferenceProperty( stepNumberPref, "max", 100 );
735 // Display parent mesh
736 int parentMeshGr = addPreference( tr( "VISU_PICKING_PREF_PARENT_MESH_TTL" ), pickingTab );
737 setPreferenceProperty( parentMeshGr, "columns", 1 );
739 addPreference( tr( "VISU_PICKING_PREF_DISPLAY_PARENT_MESH" ), parentMeshGr,
740 LightApp_Preferences::Bool, "VISU", "picking_display_parent_mesh" );
744 //---------------------------------------------------------------
747 createSpaceMousePreferences()
749 int mouseTab = addPreference( tr( "VISU_MOUSE_PREF_TAB_TLT" ) );
751 int mouseGr = addPreference( tr( "VISU_MOUSE_PREF_GROUP_TLT" ), mouseTab );
752 int mousePref = addPreference( tr( "VISU_MOUSE_PREF" ), mouseGr,
753 LightApp_Preferences::Selector, "VISU", "mouse_behaviour" );
755 values.append( tr( "VISU_MOUSE_PREF_STANDARD" ) );
756 values.append( tr( "VISU_MOUSE_PREF_KEYBOARD_FREE" ) );
757 QValueList<QVariant> indices;
760 setPreferenceProperty( mousePref, "strings", values );
761 setPreferenceProperty( mousePref, "indexes", indices );
763 int keybrdGr = addPreference( tr( "VISU_KEYBOARD_PREF_GROUP_TTL" ), mouseTab );
764 int keybrdPref = addPreference( tr( "VISU_KEYBOARD_PREF" ), keybrdGr,
765 LightApp_Preferences::IntSpin, "VISU", "speed_increment" );
766 setPreferenceProperty( keybrdPref, "max", 1000 );
768 int spacemouseGr = addPreference( tr( "VISU_SPACEMOUSE_PREF" ), mouseTab );
769 setPreferenceProperty( spacemouseGr, "columns", 1 );
770 int spacemousePref1 = addPreference( tr( "VISU_SPACEMOUSE_PREF_1" ), spacemouseGr,
771 LightApp_Preferences::Selector, "VISU",
772 "spacemouse_func1_btn" ); //decrease_speed_increment
773 int spacemousePref2 = addPreference( tr( "VISU_SPACEMOUSE_PREF_2" ), spacemouseGr,
774 LightApp_Preferences::Selector, "VISU",
775 "spacemouse_func2_btn" ); //increase_speed_increment
776 int spacemousePref3 = addPreference( tr( "VISU_SPACEMOUSE_PREF_3" ), spacemouseGr,
777 LightApp_Preferences::Selector, "VISU",
778 "spacemouse_func3_btn" ); //decrease_gauss_point_magnification
779 int spacemousePref4 = addPreference( tr( "VISU_SPACEMOUSE_PREF_4" ), spacemouseGr,
780 LightApp_Preferences::Selector, "VISU",
781 "spacemouse_func4_btn" ); //increase_gauss_point_magnification
782 int spacemousePref5 = addPreference( tr( "VISU_SPACEMOUSE_PREF_5" ), spacemouseGr,
783 LightApp_Preferences::Selector, "VISU",
784 "spacemouse_func5_btn" ); //dominant_combined_switch
786 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_1" ) );
787 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_2" ) );
788 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_3" ) );
789 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_4" ) );
790 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_5" ) );
791 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_6" ) );
792 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_7" ) );
793 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_8" ) );
794 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_*" ) );
795 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_10" ) );
796 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_11" ) );
806 indices.append( 9 ); // == button_*
807 indices.append( 10 );
808 indices.append( 11 );
809 setPreferenceProperty( spacemousePref1, "strings", values );
810 setPreferenceProperty( spacemousePref1, "indexes", indices );
811 setPreferenceProperty( spacemousePref2, "strings", values );
812 setPreferenceProperty( spacemousePref2, "indexes", indices );
813 setPreferenceProperty( spacemousePref3, "strings", values );
814 setPreferenceProperty( spacemousePref3, "indexes", indices );
815 setPreferenceProperty( spacemousePref4, "strings", values );
816 setPreferenceProperty( spacemousePref4, "indexes", indices );
817 setPreferenceProperty( spacemousePref5, "strings", values );
818 setPreferenceProperty( spacemousePref5, "indexes", indices );
822 //---------------------------------------------------------------
825 createRecorderPreferences()
827 int recorderTab = addPreference( tr( "VISU_RECORDER_PREF_TAB_TTL" ) );
829 int recorderGr = addPreference( tr( "VISU_RECORDER_PREF_GROUP_TTL" ), recorderTab );
830 setPreferenceProperty( recorderGr, "columns", 1 );
832 int modePref = addPreference( tr( "VISU_RECORDER_PREF_RECORDING_MODE" ), recorderGr,
833 LightApp_Preferences::Selector, "VISU", "recorder_mode" );
835 values.append( tr( "VISU_RECORDER_PREF_SKIPPED_FRAMES" ) );
836 values.append( tr( "VISU_RECORDER_PREF_ALL_DISLPAYED_FRAMES" ) );
837 QValueList<QVariant> indices;
840 setPreferenceProperty( modePref, "strings", values );
841 setPreferenceProperty( modePref, "indexes", indices );
843 int fpsPref = addPreference( tr( "VISU_RECORDER_PREF_FPS" ), recorderGr,
844 LightApp_Preferences::DblSpin, "VISU", "recorder_fps" );
845 setPreferenceProperty( fpsPref, "min", 0.1 );
846 setPreferenceProperty( fpsPref, "max", 100 );
848 int qualityPref = addPreference( tr( "VISU_RECORDER_PREF_QUALITY" ), recorderGr,
849 LightApp_Preferences::IntSpin, "VISU", "recorder_quality" );
850 setPreferenceProperty( qualityPref, "min", 1 );
851 setPreferenceProperty( qualityPref, "max", 100 );
853 addPreference( tr( "VISU_RECORDER_PREF_PROGRESSIVE" ), recorderGr,
854 LightApp_Preferences::Bool, "VISU", "recorder_progressive" );
858 //---------------------------------------------------------------
861 OnCreateGaussPoints()
863 double initialTime = vtkTimerLog::GetCPUTime();
864 CreatePrs3d<VISU::GaussPoints_i, VVTK_Viewer, VisuGUI_GaussPointsDlg, 1>(this);
865 INFOS( "VisuGUI_Module::OnCreateGaussPoints() : Gauss Points created in " <<
866 vtkTimerLog::GetCPUTime() - initialTime << " seconds" );
871 OnViewManagerAdded(SUIT_ViewManager* viewMgr)
873 QString type = viewMgr->getViewModel()->getType();
874 if ( type == VVTK_Viewer::Type() )
875 connect( viewMgr, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
876 this, SLOT( OnViewCreated( SUIT_ViewWindow* ) ) );
881 OnViewCreated(SUIT_ViewWindow* view)
883 SVTK_ViewWindow* viewWindow = dynamic_cast<SVTK_ViewWindow*>( view );
885 setProperty( viewWindow, "speed_increment" );
886 setProperty( viewWindow, "spacemouse_func1_btn" );
887 setProperty( viewWindow, "spacemouse_func2_btn" );
888 setProperty( viewWindow, "spacemouse_func3_btn" );
889 setProperty( viewWindow, "spacemouse_func4_btn" );
890 setProperty( viewWindow, "spacemouse_func5_btn" );
896 setProperty( SVTK_ViewWindow* viewWindow, const QString& pref )
901 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
902 SVTK_MainWindow* aMainWindow = viewWindow->getMainWindow();
904 if ( pref == "speed_increment" ) {
905 val = resMgr->integerValue( "VISU", pref, 10 );
906 aMainWindow->InvokeEvent( SVTK::SetSpeedIncrementEvent, &val );
908 else if ( pref == "spacemouse_func1_btn" ) {
909 val = resMgr->integerValue( "VISU", pref, 1 );
910 aMainWindow->InvokeEvent( SVTK::SetSMDecreaseSpeedEvent, &val );
912 else if ( pref == "spacemouse_func2_btn" ) {
913 val = resMgr->integerValue( "VISU", pref, 2 );
914 aMainWindow->InvokeEvent( SVTK::SetSMIncreaseSpeedEvent, &val );
916 else if ( pref == "spacemouse_func3_btn" ) {
917 val = resMgr->integerValue( "VISU", pref, 10 );
918 aMainWindow->InvokeEvent( VISU::SetSMDecreaseMagnificationEvent, &val );
920 else if ( pref == "spacemouse_func4_btn" ) {
921 val = resMgr->integerValue( "VISU", pref, 11 );
922 aMainWindow->InvokeEvent( VISU::SetSMIncreaseMagnificationEvent, &val );
924 else if ( pref == "spacemouse_func5_btn" ) {
925 val = resMgr->integerValue( "VISU", pref, 9 );
926 aMainWindow->InvokeEvent( SVTK::SetSMDominantCombinedSwitchEvent, &val );
932 setProperty( SVTK_ViewManager* vm, const QString& prop )
937 QPtrVector<SUIT_ViewWindow> windows = vm->getViews();
938 for ( int n = windows.count(), i = 0; i < n; i++ )
939 setProperty( dynamic_cast<SVTK_ViewWindow*>( windows[i] ), prop );
944 preferencesChanged( const QString& group, const QString& pref )
946 VisuGUI::preferencesChanged(group,pref);
948 if ( group == "VISU" && ( pref == "speed_increment" || pref == "spacemouse_func1_btn" ||
949 pref == "spacemouse_func2_btn" || pref == "spacemouse_func3_btn" ||
950 pref == "spacemouse_func4_btn" || pref == "spacemouse_func5_btn" ) ) {
952 // update properties of VVTK view windows
953 SUIT_ViewManager* vm = getApp()->getViewManager( VVTK_Viewer::Type(), false );
955 setProperty( dynamic_cast<SVTK_ViewManager*>( vm ), pref );
960 //---------------------------------------------------------------
963 getViewManager(const QString& theType,
964 const bool theIsCreate)
966 if (SUIT_ViewManager* aViewManager = VisuGUI::getViewManager(theType,theIsCreate))
969 if (theIsCreate && theType == VVTK_Viewer::Type())
970 return onCreateViewManager();
975 //---------------------------------------------------------------
980 Handle(SALOME_InteractiveObject) anIO;
981 if (VISU::Prs3d_i* aPrs3d = GetPrsToModify(this, &anIO)) {
982 // Create VVTK_ViewWindow, if it does not exist
983 if (VVTK_ViewWindow* aViewWindow = GetViewWindow<VVTK_Viewer>(this)) {
984 EditPrs3d<VISU::GaussPoints_i, VisuGUI_GaussPointsDlg, 1>(this, anIO, aPrs3d, aViewWindow);
990 //---------------------------------------------------------------
994 GetViewParams(VVTK_MainWindow* theViewWindow,
995 const char* theSuffix,
996 std::ostringstream& theStr)
998 vtkFloatingPointType aColor[3];
999 vtkRenderer* aRenderer = theViewWindow->getRenderer();
1000 aRenderer->GetBackground(aColor);
1001 Storable::DataToStream(theStr,(std::string("myColor") + theSuffix + ".R").c_str(),aColor[0]);
1002 Storable::DataToStream(theStr,(std::string("myColor") + theSuffix + ".G").c_str(),aColor[1]);
1003 Storable::DataToStream(theStr,(std::string("myColor") + theSuffix + ".B").c_str(),aColor[2]);
1005 double aPosition[3];
1006 vtkCamera* aCamera = aRenderer->GetActiveCamera();
1007 aCamera->GetPosition(aPosition);
1008 Storable::DataToStream(theStr,(std::string("myPosition") + theSuffix + "[0]").c_str(),aPosition[0]);
1009 Storable::DataToStream(theStr,(std::string("myPosition") + theSuffix + "[1]").c_str(),aPosition[1]);
1010 Storable::DataToStream(theStr,(std::string("myPosition") + theSuffix + "[2]").c_str(),aPosition[2]);
1012 double aFocalPnt[3];
1013 aCamera->GetFocalPoint(aFocalPnt);
1014 Storable::DataToStream(theStr,(std::string("myFocalPnt") + theSuffix + "[0]").c_str(),aFocalPnt[0]);
1015 Storable::DataToStream(theStr,(std::string("myFocalPnt") + theSuffix + "[1]").c_str(),aFocalPnt[1]);
1016 Storable::DataToStream(theStr,(std::string("myFocalPnt") + theSuffix + "[2]").c_str(),aFocalPnt[2]);
1019 aCamera->GetViewUp(aViewUp);
1020 Storable::DataToStream(theStr,(std::string("myViewUp") + theSuffix + "[0]").c_str(),aViewUp[0]);
1021 Storable::DataToStream(theStr,(std::string("myViewUp") + theSuffix + "[1]").c_str(),aViewUp[1]);
1022 Storable::DataToStream(theStr,(std::string("myViewUp") + theSuffix + "[2]").c_str(),aViewUp[2]);
1024 vtkFloatingPointType aParallelScale = aCamera->GetParallelScale();
1025 Storable::DataToStream(theStr,(std::string("myParallelScale") + theSuffix).c_str(),aParallelScale);
1027 double aScaleFactor[3];
1028 theViewWindow->GetScale(aScaleFactor);
1029 Storable::DataToStream(theStr,(std::string("myScaleFactor") + theSuffix + "[0]").c_str(),aScaleFactor[0]);
1030 Storable::DataToStream(theStr,(std::string("myScaleFactor") + theSuffix + "[1]").c_str(),aScaleFactor[1]);
1031 Storable::DataToStream(theStr,(std::string("myScaleFactor") + theSuffix + "[2]").c_str(),aScaleFactor[2]);
1034 //---------------------------------------------------------------
1036 SetViewParams(VVTK_MainWindow* theViewWindow,
1037 const char* theSuffix,
1038 const Storable::TRestoringMap& theMap)
1040 vtkFloatingPointType aColor[3];
1041 aColor[0] = Storable::FindValue(theMap,std::string("myColor") + theSuffix + ".R").toDouble();
1042 aColor[1] = Storable::FindValue(theMap,std::string("myColor") + theSuffix + ".G").toDouble();
1043 aColor[2] = Storable::FindValue(theMap,std::string("myColor") + theSuffix + ".B").toDouble();
1044 vtkRenderer* aRenderer = theViewWindow->getRenderer();
1045 aRenderer->SetBackground(aColor);
1047 double aPosition[3];
1048 aPosition[0] = Storable::FindValue(theMap,std::string("myPosition") + theSuffix + "[0]").toDouble();
1049 aPosition[1] = Storable::FindValue(theMap,std::string("myPosition") + theSuffix + "[1]").toDouble();
1050 aPosition[2] = Storable::FindValue(theMap,std::string("myPosition") + theSuffix + "[2]").toDouble();
1051 vtkCamera* aCamera = aRenderer->GetActiveCamera();
1052 aCamera->SetPosition(aPosition);
1054 double aFocalPnt[3];
1055 aFocalPnt[0] = Storable::FindValue(theMap,std::string("myFocalPnt") + theSuffix + "[0]").toDouble();
1056 aFocalPnt[1] = Storable::FindValue(theMap,std::string("myFocalPnt") + theSuffix + "[1]").toDouble();
1057 aFocalPnt[2] = Storable::FindValue(theMap,std::string("myFocalPnt") + theSuffix + "[2]").toDouble();
1058 aCamera->SetFocalPoint(aFocalPnt);
1061 aViewUp[0] = Storable::FindValue(theMap,std::string("myViewUp") + theSuffix + "[0]").toDouble();
1062 aViewUp[1] = Storable::FindValue(theMap,std::string("myViewUp") + theSuffix + "[1]").toDouble();
1063 aViewUp[2] = Storable::FindValue(theMap,std::string("myViewUp") + theSuffix + "[2]").toDouble();
1064 aCamera->SetViewUp(aViewUp);
1066 vtkFloatingPointType aParallelScale = Storable::FindValue(theMap,std::string("myParallelScale") + theSuffix).toDouble();
1067 aCamera->SetParallelScale(aParallelScale);
1069 double aScaleFactor[3];
1070 aScaleFactor[0] = Storable::FindValue(theMap,std::string("myScaleFactor") + theSuffix + "[0]").toDouble();
1071 aScaleFactor[1] = Storable::FindValue(theMap,std::string("myScaleFactor") + theSuffix + "[1]").toDouble();
1072 aScaleFactor[2] = Storable::FindValue(theMap,std::string("myScaleFactor") + theSuffix + "[2]").toDouble();
1073 theViewWindow->SetScale(aScaleFactor);
1076 //---------------------------------------------------------------
1078 GetViewParams(VVTK_MainWindow1* theViewWindow,
1079 std::ostringstream& theStr)
1081 GetViewParams(theViewWindow,"1",theStr);
1083 VISU_WidgetCtrl* aWidgetCtrl = theViewWindow->GetWidgetCtrl();
1084 if(aWidgetCtrl->GetEnabled()){
1085 std::string aSegmentationMode;
1086 if(aWidgetCtrl->IsPlanesActive()){
1087 VISU_PlanesWidget *aPlanesWidget = aWidgetCtrl->GetPlanesWidget();
1088 vtkFloatingPointType anOrigin[3];
1089 aPlanesWidget->GetOrigin(anOrigin);
1090 Storable::DataToStream(theStr,"myCursorOrigin[0]",anOrigin[0]);
1091 Storable::DataToStream(theStr,"myCursorOrigin[1]",anOrigin[1]);
1092 Storable::DataToStream(theStr,"myCursorOrigin[2]",anOrigin[2]);
1094 vtkFloatingPointType aNormal[3];
1095 aPlanesWidget->GetNormal(aNormal);
1096 Storable::DataToStream(theStr,"myCursorNormal[0]",aNormal[0]);
1097 Storable::DataToStream(theStr,"myCursorNormal[1]",aNormal[1]);
1098 Storable::DataToStream(theStr,"myCursorNormal[2]",aNormal[2]);
1100 vtkFloatingPointType aDepth = aPlanesWidget->Distance();
1101 Storable::DataToStream(theStr,"myCursorDepth",aDepth);
1103 aSegmentationMode = "Planes";
1104 }else if(aWidgetCtrl->IsSphereActive()){
1105 VISU_SphereWidget *aSphereWidget = aWidgetCtrl->GetSphereWidget();
1106 vtkFloatingPointType aCenter[3];
1107 aSphereWidget->GetCenter(aCenter);
1108 Storable::DataToStream(theStr,"mySphereCursorCenter[0]",aCenter[0]);
1109 Storable::DataToStream(theStr,"mySphereCursorCenter[1]",aCenter[1]);
1110 Storable::DataToStream(theStr,"mySphereCursorCenter[2]",aCenter[2]);
1112 vtkFloatingPointType aRadius = aSphereWidget->GetRadius();
1113 Storable::DataToStream(theStr,"mySphereCursorRaduis",aRadius);
1115 aSegmentationMode = "Sphere";
1118 Storable::DataToStream(theStr,"mySegmentationMode",aSegmentationMode.c_str());
1122 //---------------------------------------------------------------
1124 SetViewParams(VVTK_MainWindow1* theViewWindow,
1125 const Storable::TRestoringMap& theMap)
1127 SetViewParams(theViewWindow,"1",theMap);
1131 //---------------------------------------------------------------
1133 GetViewParams(VVTK_MainWindow2* theViewWindow,
1134 std::ostringstream& theStr)
1136 GetViewParams(theViewWindow,"2",theStr);
1140 SetViewParams(VVTK_MainWindow2* theViewWindow,
1141 const Storable::TRestoringMap& theMap)
1143 SetViewParams(theViewWindow,"2",theMap);
1147 //---------------------------------------------------------------
1149 GetViewParams(VVTK_ViewWindow* theViewWindow)
1151 std::ostringstream aStream;
1153 Storable::DataToStream(aStream,"myComment","GAUSSVIEW");
1155 SVTK_Selector* aSelector = theViewWindow->GetSelector();
1156 Selection_Mode aSelectionMode = aSelector->SelectionMode();
1157 Storable::DataToStream(aStream,"mySelectionMode",aSelectionMode);
1159 GetViewParams(theViewWindow->getMainWindow1(),aStream);
1160 GetViewParams(theViewWindow->getMainWindow2(),aStream);
1162 return aStream.str();
1165 //---------------------------------------------------------------
1173 myIsSelected(false),
1179 typedef std::map<std::string,TSelection> TVisibleEntries;
1181 struct TGetVisibleEntries
1183 TVisibleEntries& myVisibleEntries;
1185 TGetVisibleEntries(TVisibleEntries& theVisibleEntries):
1186 myVisibleEntries(theVisibleEntries)
1190 operator()(VISU_GaussPtsAct* theActor)
1192 if(theActor->GetVisibility()){
1193 const Handle(SALOME_InteractiveObject)& anIO = theActor->getIO();
1194 myVisibleEntries.insert(TVisibleEntries::value_type(anIO->getEntry(),TSelection()));
1200 GetGaussPointsSelection(VVTK_ViewWindow* theViewWindow,
1201 TVisibleEntries& theVisibleEntries)
1203 // First find all visible Gauss Points presentations
1204 vtkRenderer* aRenderer = theViewWindow->getRenderer();
1205 vtkActorCollection* anActors = aRenderer->GetActors();
1206 TGetVisibleEntries aGetVisibleEntries(theVisibleEntries);
1207 SVTK::ForEach<VISU_GaussPtsAct>(anActors,
1208 aGetVisibleEntries);
1210 // Next, find the sub-ids for the visible Gauss Points presentations
1211 SVTK_Selector* aSelector = theViewWindow->GetSelector();
1212 const SALOME_ListIO& aListIO = aSelector->StoredIObjects();
1213 SALOME_ListIteratorOfListIO anIter(aListIO);
1214 for(; anIter.More(); anIter.Next()){
1215 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
1216 std::string anEntry = anIO->getEntry();
1217 TVisibleEntries::iterator anEntriesIter = theVisibleEntries.find(anEntry);
1218 if(anEntriesIter != theVisibleEntries.end()){
1219 TSelection& aSelection = anEntriesIter->second;
1220 aSelection.myIsSelected = true;
1221 TColStd_IndexedMapOfInteger anIndexes;
1222 aSelector->GetIndex(anIO,anIndexes);
1223 if(anIndexes.Extent() > 0){
1224 aSelection.myHasSubId = true;
1225 aSelection.mySubId = anIndexes(1);
1232 //---------------------------------------------------------------
1235 CreateReference(_PTR(Study) theStudyDocument,
1236 _PTR(StudyBuilder) theStudyBuilder,
1237 _PTR(SObject) theFatherSObject,
1238 const string& theRefEntry,
1239 const TSelection& theSelection)
1241 _PTR(SObject) aNewObj = theStudyBuilder->NewObject(theFatherSObject);
1242 _PTR(SObject) aRefSObj = theStudyDocument->FindObjectID(theRefEntry);
1243 theStudyBuilder->Addreference(aNewObj,aRefSObj);
1245 std::ostringstream aStream;
1246 Storable::DataToStream(aStream,"myIsSelected",theSelection.myIsSelected);
1247 Storable::DataToStream(aStream,"myHasSubId",theSelection.myHasSubId);
1248 Storable::DataToStream(aStream,"mySubId",theSelection.mySubId);
1250 _PTR(GenericAttribute) anAttr;
1251 anAttr = theStudyBuilder->FindOrCreateAttribute(aNewObj,"AttributeComment");
1252 _PTR(AttributeComment) aComment(anAttr);
1253 aComment->SetValue(aStream.str());
1257 //---------------------------------------------------------------
1259 SetGaussPointsSelection(VisuGUI* theModule,
1260 VVTK_ViewWindow* theViewWindow,
1261 _PTR(Study) theCStudy,
1262 _PTR(SObject) theSObject)
1264 SVTK_Selector* aSelector = theViewWindow->GetSelector();
1265 aSelector->ClearIObjects();
1267 bool anIsFirst = true;
1268 _PTR(ChildIterator) aChildIter = theCStudy->NewChildIterator(theSObject);
1269 for (; aChildIter->More(); aChildIter->Next()) {
1270 _PTR(SObject) aChildSObject = aChildIter->Value();
1271 _PTR(SObject) aSObject;
1272 if(aChildSObject->ReferencedObject(aSObject)){
1273 CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObject);
1274 PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
1275 if(VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in())){
1277 VISU::UpdateViewer(theModule, aPrs3d, /*disp_only = */anIsFirst, /*highlight = */false);
1280 // To update selection
1281 _PTR(GenericAttribute) anAttr;
1282 if(aChildSObject->FindAttribute(anAttr,"AttributeComment")){
1283 _PTR(AttributeComment) aComment(anAttr);
1285 QString aStream(aComment->Value().c_str());
1286 Storable::TRestoringMap aMap;
1287 Storable::StrToMap(aStream,aMap);
1289 bool anIsSelected = Storable::FindValue(aMap,"myIsSelected").toInt();
1290 bool aHasSubId = Storable::FindValue(aMap,"myHasSubId").toInt();
1291 int aSubId = Storable::FindValue(aMap,"mySubId").toInt();
1294 std::string anEntry = aSObject->GetID();
1295 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(anEntry.c_str(),"");
1296 aSelector->AddIObject(anIO);
1298 aSelector->AddOrRemoveIndex(anIO,aSubId,false);
1305 aSelector->EndPickCallback(); // To invoke selection changed signal
1309 //---------------------------------------------------------------
1311 OnStoreConfiguration(SalomeApp_Module* theModule,
1314 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1315 if (CheckLock(aCStudy,GetDesktop(theModule)))
1318 LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
1320 SUIT_ViewManager* aViewManager = theModule->getApp()->activeViewManager();
1321 if(aViewManager->getType() == VVTK_Viewer::Type()){
1322 SUIT_ViewWindow* aWindow = aViewManager->getActiveView();
1323 VVTK_ViewWindow* aViewWindow = dynamic_cast<VVTK_ViewWindow*>(aWindow);
1325 SUIT_Study* aSStudy = aViewManager->study();
1326 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy);
1327 _PTR(Study) aCStudy = aStudy->studyDS();
1328 _PTR(StudyBuilder) aStudyBuilder = aCStudy->NewBuilder();
1330 std::string anEntry;
1331 std::string aValue = GetViewParams(aViewWindow);
1334 _PTR(SComponent) aSComponent = ClientFindOrCreateVisuComponent(aCStudy);
1336 static int myNbConfigs = 0;
1337 std::string aName = VISU::GenerateName("Config.", ++myNbConfigs).latin1();
1339 std::string aSComponentEntry = aSComponent->GetID();
1340 anEntry = CreateAttributes(aCStudy,
1341 aSComponentEntry.c_str(),
1348 SALOME_ListIO aListIO;
1349 aSelectionMgr->selectedObjects(aListIO);
1350 SALOME_ListIteratorOfListIO aListIter( aListIO );
1351 for(; aListIter.More(); aListIter.Next()){
1352 Handle(SALOME_InteractiveObject) anIO = aListIter.Value();
1353 _PTR(SObject) aSObject = aCStudy->FindObjectID(anIO->getEntry());
1354 _PTR(GenericAttribute) anAttr;
1355 if(aSObject->FindAttribute(anAttr,"AttributeComment")){
1356 _PTR(AttributeComment) aComment(anAttr);
1357 std::string aCommentValue(aComment->Value());
1358 if(aCommentValue.compare("myComment=GAUSSVIEW") >= 0){
1359 aComment->SetValue(aValue.c_str());
1360 anEntry = aSObject->GetID();
1362 _PTR(ChildIterator) aChildIter = aCStudy->NewChildIterator(aSObject);
1363 for (; aChildIter->More(); aChildIter->Next()) {
1364 _PTR(SObject) aChildSObject = aChildIter->Value();
1365 aStudyBuilder->RemoveObject(aChildSObject);
1374 TVisibleEntries aVisibleEntries;
1375 GetGaussPointsSelection(aViewWindow,
1378 _PTR(SObject) aSObject = aCStudy->FindObjectID(anEntry);
1379 _PTR(StudyBuilder) aStudyBuilder = aCStudy->NewBuilder();
1380 TVisibleEntries::const_iterator anIter = aVisibleEntries.begin();
1381 for(; anIter != aVisibleEntries.end(); anIter++){
1382 const std::string& anEntry = anIter->first;
1383 const TSelection& aSelection = anIter->second;
1385 CreateReference(aCStudy,
1392 //UpdateObjBrowser(theModule,true,aSObject);
1393 UpdateObjBrowser(theModule,true);
1399 //---------------------------------------------------------------
1400 template<class TMainWindow>
1402 SetMainWindowParams(VisuGUI* theModule,
1403 _PTR(SObject) theSObject,
1404 VVTK_ViewWindow* theViewWindow,
1405 TMainWindow* theMainWindow)
1407 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1409 _PTR(GenericAttribute) anAttr;
1410 if(theSObject->FindAttribute(anAttr,"AttributeComment")){
1411 _PTR(AttributeComment) aComment(anAttr);
1412 QString aStream(aComment->Value().c_str());
1413 Storable::TRestoringMap aMap;
1414 Storable::StrToMap(aStream,aMap);
1415 SetViewParams(theMainWindow,aMap);
1421 //---------------------------------------------------------------
1424 OnSaveConfiguration()
1426 ::OnStoreConfiguration(this,true);
1430 //---------------------------------------------------------------
1433 OnOverwriteConfiguration()
1435 ::OnStoreConfiguration(this,false);
1439 //---------------------------------------------------------------
1442 OnRestoreConfiguration()
1444 LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
1446 SALOME_ListIO aListIO;
1447 aSelectionMgr->selectedObjects(aListIO);
1448 if(aListIO.Extent() > 1)
1451 if(SUIT_ViewManager* aViewManager = getViewManager(VVTK_Viewer::Type(),true)){
1452 const Handle(SALOME_InteractiveObject)& anIO = aListIO.First();
1453 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this));
1454 _PTR(SObject) aSObject = aCStudy->FindObjectID(anIO->getEntry());
1455 myConfigSObject = aSObject;
1456 _PTR(GenericAttribute) anAttr;
1457 if(aSObject->FindAttribute(anAttr,"AttributeComment")){
1458 _PTR(AttributeComment) aComment(anAttr);
1459 QString aStream(aComment->Value().c_str());
1460 Storable::TRestoringMap aMap;
1461 Storable::StrToMap(aStream,aMap);
1462 SUIT_ViewWindow* aWindow = aViewManager->getActiveView();
1463 VVTK_ViewWindow* aViewWindow = dynamic_cast<VVTK_ViewWindow*>(aWindow);
1465 Selection_Mode aSelectionMode = Storable::FindValue(aMap,"mySelectionMode").toInt();
1466 SVTK_Selector* aSelector = aViewWindow->GetSelector();
1467 aSelector->SetSelectionMode(aSelectionMode);
1469 SetGaussPointsSelection(this,aViewWindow,aCStudy,aSObject);
1471 std::string aSegmentationMode;
1472 if(VVTK_MainWindow1* aMainWindow = aViewWindow->getMainWindow1()){
1473 aMainWindow->SetPlanesSegementation(false);
1474 aMainWindow->SetSphereSegementation(false);
1475 VISU_WidgetCtrl* aWidgetCtrl = aMainWindow->GetWidgetCtrl();
1476 aSegmentationMode = Storable::FindValue(aMap,"mySegmentationMode").latin1();
1478 if(aSegmentationMode == "Planes"){
1479 VISU_PlanesWidget *aPlanesWidget = aWidgetCtrl->GetPlanesWidget();
1480 vtkFloatingPointType anOrigin[3];
1481 anOrigin[0] = Storable::FindValue(aMap,"myCursorOrigin[0]").toDouble();
1482 anOrigin[1] = Storable::FindValue(aMap,"myCursorOrigin[1]").toDouble();
1483 anOrigin[2] = Storable::FindValue(aMap,"myCursorOrigin[2]").toDouble();
1484 aPlanesWidget->SetOrigin(anOrigin);
1486 vtkFloatingPointType aNormal[3];
1487 aNormal[0] = Storable::FindValue(aMap,"myCursorNormal[0]").toDouble();
1488 aNormal[1] = Storable::FindValue(aMap,"myCursorNormal[1]").toDouble();
1489 aNormal[2] = Storable::FindValue(aMap,"myCursorNormal[2]").toDouble();
1490 aPlanesWidget->SetNormal(aNormal);
1492 vtkFloatingPointType aDepth = Storable::FindValue(aMap,"myCursorDepth").toDouble();
1493 aPlanesWidget->SetDistance(aDepth);
1495 aMainWindow->SetPlanesSegementation(true);
1496 }else if(aSegmentationMode == "Sphere"){
1497 VISU_SphereWidget *aSphereWidget = aWidgetCtrl->GetSphereWidget();
1498 vtkFloatingPointType aCenter[3];
1499 aCenter[0] = Storable::FindValue(aMap,"mySphereCursorCenter[0]").toDouble();
1500 aCenter[1] = Storable::FindValue(aMap,"mySphereCursorCenter[1]").toDouble();
1501 aCenter[2] = Storable::FindValue(aMap,"mySphereCursorCenter[2]").toDouble();
1502 aSphereWidget->SetCenter(aCenter);
1504 vtkFloatingPointType aRadius = Storable::FindValue(aMap,"mySphereCursorRaduis").toDouble();
1505 aSphereWidget->SetRadius(aRadius);
1507 aMainWindow->SetSphereSegementation(true);
1511 if(VVTK_MainWindow1* aMainWindow = aViewWindow->getMainWindow1()){
1512 SVTK_RenderWindowInteractor* anInteractor = aMainWindow->GetInteractor();
1513 if(anInteractor->isVisible()){
1514 SetMainWindowParams(this,myConfigSObject,aViewWindow,aMainWindow);
1516 anInteractor->installEventFilter(this);
1519 if(aSegmentationMode != ""){
1520 if(VVTK_MainWindow2* aMainWindow = aViewWindow->getMainWindow2()){
1521 SVTK_RenderWindowInteractor* anInteractor = aMainWindow->GetInteractor();
1522 if(anInteractor->isVisible())
1523 SetMainWindowParams(this,myConfigSObject,aViewWindow,aMainWindow);
1525 anInteractor->installEventFilter(this);
1529 SetGaussPointsSelection(this,aViewWindow,aCStudy,aSObject);
1535 //---------------------------------------------------------------
1538 eventFilter( QObject * theWatched, QEvent * theEvent )
1540 bool aRet = VisuGUI::eventFilter(theWatched,theEvent);
1541 if(theEvent->type() == QEvent::Show){
1542 if(SUIT_ViewManager* aViewManager = getViewManager(VVTK_Viewer::Type(),false)){
1543 SUIT_ViewWindow* aWindow = aViewManager->getActiveView();
1544 VVTK_ViewWindow* aViewWindow = dynamic_cast<VVTK_ViewWindow*>(aWindow);
1545 if(VVTK_MainWindow1* aMainWindow = aViewWindow->getMainWindow1()){
1546 SVTK_RenderWindowInteractor* anInteractor = aMainWindow->GetInteractor();
1547 if(theWatched == anInteractor){
1548 SetMainWindowParams(this,myConfigSObject,aViewWindow,aMainWindow);
1549 anInteractor->removeEventFilter(this);
1552 if(VVTK_MainWindow2* aMainWindow = aViewWindow->getMainWindow2()){
1553 SVTK_RenderWindowInteractor* anInteractor = aMainWindow->GetInteractor();
1554 if(theWatched == aMainWindow->GetInteractor()){
1555 SetMainWindowParams(this,myConfigSObject,aViewWindow,aMainWindow);
1556 anInteractor->removeEventFilter(this);
1565 const char gSeparator = '_'; // character used to separate parameter names
1566 const char gDigitsSep = ':'; // character used to separate numeric parameter values (color = r:g:b)
1568 * \brief Virtual public
1570 * This method is called just before the study document is saved, so the module has a possibility
1571 * to store visual parameters in AttributeParameter attribue(s)
1573 void VisuGUI_Module::storeVisualParameters(int savePoint)
1575 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
1576 if( !study || !study->studyDS() )
1578 _PTR(Study) studyDS = study->studyDS();
1579 _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative", moduleName().latin1(), savePoint);
1580 _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
1582 // viewers counters are used for storing view_numbers in IParameters
1583 int svtkViewers( 0 ), vvtkViewers( 0 ), plotViewers( 0 );
1585 // componentName is used for encoding of entries when storing them in IParameters
1586 _PTR(SComponent) visuEng = ClientFindOrCreateVisuComponent( studyDS );
1587 std::string componentName = visuEng->ComponentDataType();
1589 QPtrList<SUIT_ViewManager> lst;
1591 // saving VVTK viewer parameters. VVTK (Gauss Viewers) are NOT created by SalomeApp since
1592 // VVTK is declared in VISU, so here we store VVTK view window parameters.
1593 // VisuGUI_Module::restoreVisualParameters() creates VVTK_Views and restores its parameters.
1594 ip->setProperty( "ActiveGaussViewer", "-1" );
1595 getApp()->viewManagers( VVTK_Viewer::Type(), lst );
1596 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it ) {
1597 SUIT_ViewManager* vman = it.current();
1598 if ( SUIT_ViewWindow* vwin = vman->getActiveView() ) {
1599 // using predefined string "GaussViewer" as "entry".. it's a hardcoded "workaround".
1600 // gauss viewer parameters are retrieved using this "entry" string.
1601 // name of parameter = caption of gauss ViewWindow
1602 // value of parameter = ViewWindow's visual parameters
1603 ip->setParameter( "GaussViewer", vwin->caption().latin1(), vwin->getVisualParameters().latin1() );
1605 if ( application()->desktop()->activeWindow() == vwin )
1606 ip->setProperty( "ActiveGaussViewer", QString::number( vvtkViewers ).latin1() );
1611 // VISU module opens one SVTK viewer in activateModule(). This causes a bug in save-restore visual
1612 // parameters: it no SVTK view was saved, we need NOT any SVTK on restore. Here we store if any is open..
1615 getApp()->viewManagers( SVTK_Viewer::Type(), lst );
1616 ip->setProperty( "VtkViewersCount", QString::number( lst.count() ).latin1() );
1619 // main cycle to store parameters of displayed objects
1621 getApp()->viewManagers( lst );
1622 vvtkViewers = svtkViewers = plotViewers = 0;
1623 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it ) {
1624 SUIT_ViewManager* vman = it.current();
1625 QString vType = vman->getType();
1626 int* viewsCounter = vType == SVTK_Viewer::Type() ? &svtkViewers :
1627 vType == VVTK_Viewer::Type() ? &vvtkViewers :
1628 vType == SPlot2d_Viewer::Type() ? &plotViewers : 0;
1630 // saving VTK actors' properties
1631 if ( vType == SVTK_Viewer::Type() || // processing SVTK and VVTK viewers in the same
1632 vType == VVTK_Viewer::Type() ) { // way (VVTK_ViewWindow inherits SVTK_ViewWindow)
1634 QPtrVector<SUIT_ViewWindow> views = vman->getViews();
1635 for ( int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++ ) {
1636 if ( SVTK_ViewWindow* vtkView = dynamic_cast<SVTK_ViewWindow*>( views[i] ) ) {
1637 vtkActorCollection* allActors = vtkView->getRenderer()->GetActors();
1638 allActors->InitTraversal();
1639 while ( vtkActor* actor = allActors->GetNextActor() ) {
1640 if ( actor->GetVisibility() ) { // store only visible actors
1641 if ( VISU_Actor* vActor = VISU_Actor::SafeDownCast( actor ) ) {
1642 if ( vActor->hasIO() ) { // actor corresponds to existing obj
1644 Handle(SALOME_InteractiveObject) io = vActor->getIO();
1645 // entry is "ecoded" = it does NOT contain component adress, since it is a
1646 // subject to change on next component loading
1647 std::string entry = ip->encodeEntry( io->getEntry(), componentName );
1649 std::string param, vtkParam = vType.latin1(); vtkParam += gSeparator;
1650 vtkParam += QString::number( *viewsCounter ).latin1(); vtkParam += gSeparator;
1652 param = vtkParam + "Visibility";
1653 ip->setParameter( entry, param, "On" );
1654 param = vtkParam + "Name";
1655 ip->setParameter( entry, param, vActor->getName() );
1656 param = vtkParam + "RepresentationMode";
1657 ip->setParameter( entry, param, QString::number( vActor->GetRepresentation() ).latin1() );
1658 param = vtkParam + "Opacity";
1659 ip->setParameter( entry, param, QString::number( vActor->GetOpacity() ).latin1() );
1660 vtkFloatingPointType r, g, b;
1661 vActor->GetColor(r, g, b);
1662 QString colorStr = QString::number( r ); colorStr += gDigitsSep;
1663 colorStr += QString::number( g ); colorStr += gDigitsSep;
1664 colorStr += QString::number( b );
1665 param = vtkParam + "Color";
1666 ip->setParameter( entry, param, colorStr.latin1() );
1667 param = vtkParam + "LineWidth";
1668 ip->setParameter( entry, param, QString::number( vActor->GetLineWidth() ).latin1() );
1669 if ( vActor->IsShrunkable() && vActor->IsShrunk() ) {
1670 param = vtkParam + "ShrinkMode";
1671 ip->setParameter( entry, param, "On" );
1672 param = vtkParam + "ShrinkFactor";
1673 ip->setParameter( entry, param, QString::number( vActor->GetShrinkFactor() ).latin1() );
1675 VISU_ScalarMapAct* scalarMapActor = dynamic_cast<VISU_ScalarMapAct*>( vActor );
1676 if ( scalarMapActor && scalarMapActor->IsShading() ) {
1677 param = vtkParam + "Shading";
1678 ip->setParameter( entry, param, "On" );
1680 if ( const VISU::Prs3d_i* vPrs = vActor->GetPrs3d() ) {
1681 param = vtkParam + "ClippingPlane";
1682 int nPlanes = vPrs->GetNumberOfClippingPlanes();
1684 ip->setParameter( entry, param, "Off" );
1685 for ( int p = 0; p < nPlanes; p++ ) {
1686 vtkPlane* plane = vPrs->GetClippingPlane( p );
1687 vtkFloatingPointType normal[3], origin[3];
1688 plane->GetNormal( normal );
1689 plane->GetOrigin( origin );
1690 std::string planeValue = QString::number( normal[0] ).latin1(); planeValue += gDigitsSep;
1691 planeValue += QString::number( normal[1] ).latin1(); planeValue += gDigitsSep;
1692 planeValue += QString::number( normal[2] ).latin1(); planeValue += gDigitsSep;
1693 planeValue += QString::number( origin[0] ).latin1(); planeValue += gDigitsSep;
1694 planeValue += QString::number( origin[1] ).latin1(); planeValue += gDigitsSep;
1695 planeValue += QString::number( origin[2] ).latin1();
1696 param = QString( "%1ClippingPlane_%2" ).arg( vtkParam.c_str() ).arg( p+1 ).latin1();
1697 ip->setParameter( entry, param, planeValue );
1702 } // salome_actor successfull downcast
1704 } // end of ..while.. actors traversal
1708 } // if ( SVTK view model )
1709 else if ( vType == SPlot2d_Viewer::Type() ) { // processing Plot2d viewers
1710 QPtrVector<SUIT_ViewWindow> views = vman->getViews();
1711 for ( int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++ ) {
1712 if ( Plot2d_ViewWindow* plotView = dynamic_cast<Plot2d_ViewWindow*>( views[i] ) ) {
1713 Plot2d_ViewFrame* plotVF = plotView->getViewFrame();
1714 QPtrList<Plot2d_Curve> curves;
1715 plotVF->getCurves( curves );
1717 Plot2d_Curve* curve;
1718 for ( curve = curves.first(); curve; curve = curves.next() ) {
1719 if ( SPlot2d_Curve* sCurve = dynamic_cast<SPlot2d_Curve*>( curve ) ) {
1720 if ( sCurve->hasIO() ) {
1722 Handle(SALOME_InteractiveObject) io = sCurve->getIO();
1723 // entry is "ecoded" = it does NOT contain component adress, since it is a
1724 // subject to change on next component loading
1725 std::string entry = ip->encodeEntry( io->getEntry(), componentName );
1727 std::string param, plotParam = vType.latin1(); plotParam += gSeparator;
1728 plotParam += QString::number( *viewsCounter ).latin1(); plotParam += gSeparator;
1730 param = plotParam + "Visibility";
1731 ip->setParameter( entry, param, "On" );
1735 } // if ( plotView )
1738 } // if ( SPlot2d view model )
1742 // returns VISU_Actor with IO with given entry
1743 VISU_Actor* getActor( const QString& entry, SVTK_ViewWindow* vtkView )
1745 if ( vtkView && !entry.isEmpty() ) {
1746 vtkActorCollection* allActors = vtkView->getRenderer()->GetActors();
1747 allActors->InitTraversal();
1748 while ( vtkActor* actor = allActors->GetNextActor() ) {
1749 if ( VISU_Actor* vActor = VISU_Actor::SafeDownCast( actor ) ) {
1750 if ( vActor->hasIO() ) { // actor corresponds to existing obj
1751 Handle(SALOME_InteractiveObject) io = vActor->getIO();
1752 if ( entry == io->getEntry() )
1761 const int ViewerType = 0;
1762 const int ViewIndex = 1;
1763 const int ParamName = 2;
1764 // visual parameters are stored in strings as follows:
1765 // ViewerType_ViewNumber_ParamName. '_' is used as separator and should not be used in
1766 // viewer type or parameter names
1768 // return viewer type substring from parameter name
1769 std::string getParam( const std::string& paramName, const int index )
1771 QStringList lst = QStringList::split( gSeparator, QString( paramName.c_str() ) );
1772 if ( !lst.isEmpty() && index < lst.size() )
1773 return lst[index].latin1();
1779 * \brief Virtual public
1781 * This method is called after the study document is opened, so the module has a possibility to restore
1784 void VisuGUI_Module::restoreVisualParameters(int savePoint)
1786 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
1787 if( !study || !study->studyDS() )
1789 _PTR(Study) studyDS = study->studyDS();
1790 _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative", moduleName().latin1(), savePoint);
1791 _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
1793 // actors are stored in a map after displaying of them for quicker access in future
1794 QMap<QString, QMap<QString, VISU_Actor*> > vtkActors; // map: entry to map: ViewType_<ID> to actor (SVTK/VVTK)
1796 std::vector<std::string> entries = ip->getEntries();
1798 for ( std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt ) {
1800 std::vector<std::string> paramNames = ip->getAllParameterNames( *entIt );
1801 std::vector<std::string> paramValues = ip->getAllParameterValues( *entIt );
1802 std::vector<std::string>::iterator namesIt = paramNames.begin();
1803 std::vector<std::string>::iterator valuesIt = paramValues.begin();
1805 if ( *entIt == "GaussViewer" ) {
1806 // parameter names are view window's captions, values - visual parameters.
1807 for ( ; namesIt != paramNames.end(); ++namesIt, ++valuesIt ) {
1808 SUIT_ViewManager* vman = onCreateViewManager();
1809 SUIT_ViewWindow* vwin = vman->getActiveView();
1810 vwin->setCaption( (*namesIt).c_str() );
1812 // wait untill the window is really shown. This step fixes MANY bugs..
1813 while ( !vwin->isVisible() )
1814 qApp->processEvents();
1816 vwin->setVisualParameters( (*valuesIt).c_str() );
1818 continue; // skip to next entry
1821 // entry is a normal entry - it should be "decoded" (setting base adress of component)
1822 QString entry( ip->decodeEntry( *entIt ).c_str() );
1824 //SRN: Added a check that the entry corresponds to Standard_Real object in the Study
1825 // as the object may be deleted or modified after the visual state is saved.
1826 _PTR(SObject) so = studyDS->FindObjectID(entry.latin1());
1827 if(!so) continue; //Skip the not existent entry
1829 for ( ; namesIt != paramNames.end(); ++namesIt, ++valuesIt ) {
1830 std::string viewerType = ::getParam( *namesIt, ViewerType );
1832 std::string paramName = ::getParam( *namesIt, ParamName );
1834 std::string viewIndexStr = ::getParam( *namesIt, ViewIndex );
1835 int viewIndex = QString( viewIndexStr.c_str() ).toUInt( &ok );
1836 if ( !ok ) // bad conversion of view index to integer
1839 // cout << " -- " << viewerType << ": entry = " << entry.latin1() << ", paramName = " << paramName << endl;
1841 if ( viewerType == SVTK_Viewer::Type().latin1() ||
1842 viewerType == VVTK_Viewer::Type().latin1() ) {
1844 // used as inner map key for locating the actor.
1845 QString viewerTypeIndex = QString( viewerType.c_str() ) + QString::number( viewIndex );
1847 if ( paramName == "Visibility" && displayer() ) {
1848 // if VVTK, then we must create viewer first, because
1850 QPtrList<SUIT_ViewManager> lst;
1851 getApp()->viewManagers( viewerType.c_str(), lst );
1853 // SVTK/VVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
1854 if ( viewIndex >= 0 && viewIndex < lst.count() ) {
1855 SUIT_ViewManager* vman = lst.at( viewIndex );
1856 SUIT_ViewModel* vmodel = vman->getViewModel();
1857 // both SVTK and VVTK view models can be casted to SALOME_View
1858 displayer()->Display( entry, true, dynamic_cast<SALOME_View*>( vmodel ) );
1860 // store displayed actor in a temporary map for quicker access later when restoring other parameters
1861 SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
1862 QMap<QString, VISU_Actor*> viewActorMap;
1863 if ( vtkActors.contains( entry ) )
1864 viewActorMap = vtkActors[ entry ];
1865 viewActorMap[ viewerTypeIndex ] = getActor( entry, vtkView );
1866 vtkActors[ entry ] = viewActorMap;
1869 else { // the rest properties "work" with VISU_Actor, so we initialize it at first
1870 VISU_Actor* vActor = 0;
1871 if ( vtkActors.contains( entry ) ) {
1872 QMap<QString, VISU_Actor*> viewActorMap = vtkActors[ entry ];
1873 if ( viewActorMap.contains( viewerTypeIndex ) )
1874 vActor = viewActorMap[ viewerTypeIndex ];
1879 QString val( (*valuesIt).c_str() );
1881 if ( paramName == "Name" )
1882 vActor->setName( val.latin1() );
1884 else if ( paramName == "RepresentationMode" )
1885 vActor->SetRepresentation( val.toInt() );
1887 else if ( paramName == "Opacity" )
1888 vActor->SetOpacity( val.toFloat() );
1890 else if ( paramName == "Color" ) {
1891 QStringList colors = QStringList::split( gDigitsSep, val );
1892 if ( colors.count() == 3 )
1893 vActor->SetColor( colors[0].toFloat(), colors[1].toFloat(), colors[2].toFloat() );
1896 else if ( paramName == "LineWidth" )
1897 vActor->SetLineWidth( val.toFloat() );
1899 else if ( paramName == "ShrinkMode" ) {
1900 vActor->SetShrinkable( true );
1901 vActor->SetShrink();
1904 else if ( paramName == "ShrunkFactor" )
1905 vActor->SetShrinkFactor( val.toFloat() );
1907 else if ( paramName == "Shading" ) {
1908 if ( VISU_ScalarMapAct* scalarMapActor = dynamic_cast<VISU_ScalarMapAct*>( vActor ) )
1909 scalarMapActor->SetShading();
1912 else if ( paramName.find( "ClippingPlane" ) != std::string::npos ) {
1913 VISU::Prs3d_i* prs = vActor->GetPrs3d();
1917 prs->RemoveAllClippingPlanes();
1918 if ( val != "Off" ) {
1919 QStringList vals = QStringList::split( gDigitsSep, val );
1920 if ( vals.count() == 6 ) { // format check: 6 float values
1921 vtkFloatingPointType normal[3], origin[3];
1922 for (int x = 0; x < 3; x++ ) {
1923 normal[x] = vals[x].toFloat();
1924 origin[x] = vals[x+3].toFloat();
1926 OrientedPlane* plane = OrientedPlane::New();
1927 plane->SetNormal( normal );
1928 plane->SetOrigin( origin );
1929 prs->AddClippingPlane( plane );
1937 else if ( viewerType == SPlot2d_Viewer::Type().latin1() ) {
1939 if ( paramName == "Visibility" && displayer() ) {
1940 QPtrList<SUIT_ViewManager> lst;
1941 getApp()->viewManagers( viewerType.c_str(), lst );
1943 if ( viewIndex >= 0 && viewIndex < lst.count() ) {
1944 SUIT_ViewManager* vman = lst.at( viewIndex );
1945 SUIT_ViewModel* vmodel = vman->getViewModel();
1946 // SVTK and VVTK view models can be casted to SALOME_View
1947 displayer()->Display( entry, true, dynamic_cast<SALOME_View*>( vmodel ) );
1953 } // for names/parameters iterator
1954 } // for entries iterator
1956 // [ update all SVTK/VVTK/Plot2D views
1957 QPtrList<SUIT_ViewManager> lst;
1958 getApp()->viewManagers( lst );
1959 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it ) {
1960 SUIT_ViewManager* vman = it.current();
1961 SUIT_ViewModel* vmodel = vman->getViewModel();
1964 if ( vmodel->getType() == SVTK_Viewer::Type() || // processing SVTK and VVTK viewers
1965 vmodel->getType() == VVTK_Viewer::Type() ) { // in the same way
1966 SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
1967 vtkView->getRenderer()->ResetCameraClippingRange();
1970 else if ( vmodel->getType() == SPlot2d_Viewer::Type().latin1() ) {
1971 Plot2d_ViewWindow* plotView = (Plot2d_ViewWindow*) vman->getActiveView();
1972 plotView->getViewFrame()->Repaint();
1974 } // ] end of update views
1976 // VISU module opens one SVTK viewer in activateModule(). This causes a bug in save-restore visual
1977 // parameters: it no SVTK view was saved, we need NOT any SVTK on restore. Here we close one
1978 // default SVTK if needed.
1980 QString openedSvtkViewerStr = ip->getProperty( "VtkViewersCount" ).c_str();
1981 int openedSvtkViewer = openedSvtkViewerStr.toInt( &ok );
1982 if ( ok && openedSvtkViewer == 0 ) {
1984 getApp()->viewManagers( SVTK_Viewer::Type(), lst );
1986 lst.at( 0 )->closeAllViews();
1990 // if active Gauss Viewer is set ( != -1) then raise the gauss view window.
1992 QString activeGaussViewerStr = ip->getProperty( "ActiveGaussViewer" ).c_str();
1993 int activeGaussViewer = activeGaussViewerStr.toInt( &ok );
1994 if ( ok && activeGaussViewer != -1 ) {
1996 getApp()->viewManagers( VVTK_Viewer::Type(), lst );
1997 if ( activeGaussViewer >= 0 && activeGaussViewer < lst.count() ) {
1998 SUIT_ViewWindow* activeView = lst.at( activeGaussViewer )->getActiveView();
2000 activeView->setActiveWindow();
2001 activeView->setFocus();