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 VVTK_ViewManager* aViewManager = new VVTK_ViewManager( anApp->activeStudy(), anApp->desktop() );
346 VVTK_Viewer* aViewer = (VVTK_Viewer*)aViewManager->getViewModel();
347 new LightApp_VTKSelector( aViewer, anApp->selectionMgr() );
348 anApp->addViewManager( aViewManager );
350 //aViewer->setBackgroundColor( Qt::darkGreen );
351 aViewManager->createViewWindow();
353 return aViewer->getViewManager();
357 //---------------------------------------------------------------
362 VisuGUI::createPreferences();
364 createGaussPointsPreferences();
365 createInsideCursorPreferences();
366 createOutsideCursorPreferences();
367 createPickingPreferences();
368 createSpaceMousePreferences();
369 createRecorderPreferences();
373 //---------------------------------------------------------------
376 createGaussPointsPreferences()
378 int gaussTab = addPreference( tr( "VISU_GAUSS_PREF_TAB_TTL" ) );
379 int primitiveGr = addPreference( tr( "VISU_GAUSS_PREF_PRIMITIVE_GROUP_TTL" ), gaussTab );
380 setPreferenceProperty( primitiveGr, "columns", 1 );
382 int primitiveTypePref = addPreference( tr( "VISU_GAUSS_PREF_PRIMITIVE_TYPE" ), primitiveGr,
383 LightApp_Preferences::Selector, "VISU",
384 "point_sprite_primitive_type" );
387 values.append( tr( "VISU_GAUSS_PREF_POINTSPRITE" ) );
388 values.append( tr( "VISU_GAUSS_PREF_OPENGLPOINT" ) );
389 values.append( tr( "VISU_GAUSS_PREF_GEOMSPHERE" ) );
390 QValueList<QVariant> indices;
394 setPreferenceProperty( primitiveTypePref, "strings", values );
395 setPreferenceProperty( primitiveTypePref, "indexes", indices );
397 int clampPref = addPreference( tr( "VISU_GAUSS_PREF_CLAMP" ), primitiveGr,
398 LightApp_Preferences::IntSpin, "VISU", "point_sprite_clamp" );
399 setPreferenceProperty( clampPref, "min", 1 );
400 setPreferenceProperty( clampPref, "max", 512 );
402 addPreference( tr( "VISU_GAUSS_PREF_MAIN_TEXTURE" ), primitiveGr,
403 LightApp_Preferences::File, "VISU", "point_sprite_main_texture" );
405 addPreference( tr( "VISU_GAUSS_PREF_ALPHA_TEXTURE" ), primitiveGr,
406 LightApp_Preferences::File, "VISU", "point_sprite_alpha_texture" );
408 int alphaThresholdPref = addPreference( tr( "VISU_GAUSS_PREF_ALPHA_THRESHOLD" ), primitiveGr,
409 LightApp_Preferences::DblSpin, "VISU",
410 "point_sprite_alpha_threshold" );
411 setPreferenceProperty( alphaThresholdPref, "min", 0.0 );
412 setPreferenceProperty( alphaThresholdPref, "max", 1.0 );
413 setPreferenceProperty( alphaThresholdPref, "step", 0.1 );
415 int resolutionPref = addPreference( tr( "VISU_GAUSS_PREF_RESOLUTION" ), primitiveGr,
416 LightApp_Preferences::IntSpin, "VISU", "geom_sphere_resolution" );
417 setPreferenceProperty( resolutionPref, "min", 3 );
418 setPreferenceProperty( resolutionPref, "max", 100 );
420 int faceLimitPref = addPreference( tr( "VISU_GAUSS_PREF_FACE_LIMIT" ), primitiveGr,
421 LightApp_Preferences::IntSpin, "VISU", "geom_sphere_face_limit" );
422 setPreferenceProperty( faceLimitPref, "min", 10 );
423 setPreferenceProperty( faceLimitPref, "max", 1000000 );
425 int sizeGr = addPreference( tr( "VISU_GAUSS_PREF_SIZE_GROUP_TTL" ), gaussTab );
426 setPreferenceProperty( sizeGr, "columns", 2 );
428 int minSizePref = addPreference( tr( "VISU_GAUSS_PREF_MIN_SIZE" ), sizeGr,
429 LightApp_Preferences::IntSpin, "VISU", "point_sprite_min_size" );
430 setPreferenceProperty( minSizePref, "min", 1 );
431 setPreferenceProperty( minSizePref, "max", 100 );
433 int maxSizePref = addPreference( tr( "VISU_GAUSS_PREF_MAX_SIZE" ), sizeGr,
434 LightApp_Preferences::IntSpin, "VISU", "point_sprite_max_size" );
435 setPreferenceProperty( maxSizePref, "min", 1 );
436 setPreferenceProperty( maxSizePref, "max", 100 );
438 int magnificationPref = addPreference( tr( "VISU_GAUSS_PREF_MAGNIFICATION" ), sizeGr,
439 LightApp_Preferences::IntSpin, "VISU",
440 "point_sprite_magnification" );
441 setPreferenceProperty( magnificationPref, "min", 10 );
442 setPreferenceProperty( magnificationPref, "max", 1000 );
444 int incrementPref = addPreference( tr( "VISU_GAUSS_PREF_INCREMENT" ), sizeGr,
445 LightApp_Preferences::DblSpin, "VISU", "point_sprite_increment" );
446 setPreferenceProperty( incrementPref, "min", 0.01 );
447 setPreferenceProperty( incrementPref, "max", 10 );
448 setPreferenceProperty( incrementPref, "step", 0.1 );
450 int geomGr = addPreference( tr( "VISU_GAUSS_PREF_GEOM_GROUP_TTL" ), gaussTab );
451 setPreferenceProperty( geomGr, "columns", 1 );
453 int sizePref = addPreference( tr( "VISU_GAUSS_PREF_SIZE" ), geomGr,
454 LightApp_Preferences::IntSpin, "VISU", "point_sprite_size" );
455 setPreferenceProperty( sizePref, "min", 1 );
456 setPreferenceProperty( sizePref, "max", 100 );
458 addPreference( tr( "VISU_GAUSS_PREF_COLOR" ), geomGr,
459 LightApp_Preferences::Color, "VISU", "point_sprite_color" );
461 // ScalarBar Preferences
462 int scalarBarGr = addPreference( tr( "VISU_GAUSS_SCALAR_BAR_PREF_GROUP_TTL" ), gaussTab );
463 setPreferenceProperty( scalarBarGr, "columns", 1 );
465 int activeBarPref = addPreference( tr( "VISU_GAUSS_PREF_ACTIVE_BAR" ), scalarBarGr,
466 LightApp_Preferences::Selector, "VISU", "scalar_bar_active_local" );
469 values.append( tr( "VISU_GAUSS_PREF_LOCAL" ) );
470 values.append( tr( "VISU_GAUSS_PREF_GLOBAL" ) );
474 setPreferenceProperty( activeBarPref, "strings", values );
475 setPreferenceProperty( activeBarPref, "indexes", indices );
477 addPreference( tr( "VISU_GAUSS_PREF_DISPLAY_GLOBAL" ), scalarBarGr,
478 LightApp_Preferences::Bool, "VISU", "scalar_bar_display_global" );
480 int colorPref = addPreference( tr( "VISU_GAUSS_PREF_SCALAR_BAR_MODE" ), scalarBarGr,
481 LightApp_Preferences::Selector, "VISU", "scalar_bar_bicolor" );
484 values.append( tr( "VISU_GAUSS_PREF_BICOLOR" ) );
485 values.append( tr( "VISU_GAUSS_PREF_RAINBOW" ) );
489 setPreferenceProperty( colorPref, "strings", values );
490 setPreferenceProperty( colorPref, "indexes", indices );
492 int spacingPref = addPreference( tr( "VISU_GAUSS_PREF_SPACING" ), scalarBarGr,
493 LightApp_Preferences::DblSpin, "VISU", "scalar_bar_spacing" );
494 setPreferenceProperty( spacingPref, "min", 0.01 );
495 setPreferenceProperty( spacingPref, "max", 1.0 );
496 setPreferenceProperty( spacingPref, "step", 0.01 );
500 //---------------------------------------------------------------
503 createInsideCursorPreferences()
505 int insideCursorTab = addPreference( tr( "VISU_GAUSS_INSIDE_CURSOR_PREF_TAB_TTL" ) );
507 int primitiveGr = addPreference( tr( "VISU_GAUSS_PREF_PRIMITIVE_GROUP_TTL" ), insideCursorTab );
508 setPreferenceProperty( primitiveGr, "columns", 1 );
510 int primitiveTypePref = addPreference( tr( "VISU_GAUSS_PREF_PRIMITIVE_TYPE" ), primitiveGr,
511 LightApp_Preferences::Selector, "VISU",
512 "inside_point_sprite_primitive_type" );
515 values.append( tr( "VISU_GAUSS_PREF_POINTSPRITE" ) );
516 values.append( tr( "VISU_GAUSS_PREF_OPENGLPOINT" ) );
517 values.append( tr( "VISU_GAUSS_PREF_GEOMSPHERE" ) );
518 QValueList<QVariant> indices;
522 setPreferenceProperty( primitiveTypePref, "strings", values );
523 setPreferenceProperty( primitiveTypePref, "indexes", indices );
525 int clampPref = addPreference( tr( "VISU_GAUSS_PREF_CLAMP" ), primitiveGr,
526 LightApp_Preferences::IntSpin, "VISU", "inside_point_sprite_clamp" );
527 setPreferenceProperty( clampPref, "min", 1 );
528 setPreferenceProperty( clampPref, "max", 512 );
530 addPreference( tr( "VISU_GAUSS_PREF_MAIN_TEXTURE" ), primitiveGr,
531 LightApp_Preferences::File, "VISU", "inside_point_sprite_main_texture" );
533 addPreference( tr( "VISU_GAUSS_PREF_ALPHA_TEXTURE" ), primitiveGr,
534 LightApp_Preferences::File, "VISU", "inside_point_sprite_alpha_texture" );
536 int alphaThresholdPref = addPreference( tr( "VISU_GAUSS_PREF_ALPHA_THRESHOLD" ), primitiveGr,
537 LightApp_Preferences::DblSpin, "VISU",
538 "inside_point_sprite_alpha_threshold" );
539 setPreferenceProperty( alphaThresholdPref, "min", 0.0 );
540 setPreferenceProperty( alphaThresholdPref, "max", 1.0 );
541 setPreferenceProperty( alphaThresholdPref, "step", 0.1 );
543 int resolutionPref = addPreference( tr( "VISU_GAUSS_PREF_RESOLUTION" ), primitiveGr,
544 LightApp_Preferences::IntSpin, "VISU",
545 "inside_geom_sphere_resolution" );
546 setPreferenceProperty( resolutionPref, "min", 3 );
547 setPreferenceProperty( resolutionPref, "max", 100 );
549 int faceLimitPref = addPreference( tr( "VISU_GAUSS_PREF_FACE_LIMIT" ), primitiveGr,
550 LightApp_Preferences::IntSpin, "VISU",
551 "inside_geom_sphere_face_limit" );
552 setPreferenceProperty( faceLimitPref, "min", 10 );
553 setPreferenceProperty( faceLimitPref, "max", 1000000 );
555 int sizeGr = addPreference( tr( "VISU_GAUSS_PREF_SIZE_GROUP_TTL" ), insideCursorTab );
556 setPreferenceProperty( sizeGr, "columns", 2 );
558 int minSizePref = addPreference( tr( "VISU_GAUSS_PREF_MIN_SIZE" ), sizeGr,
559 LightApp_Preferences::IntSpin, "VISU",
560 "inside_point_sprite_min_size" );
561 setPreferenceProperty( minSizePref, "min", 1 );
562 setPreferenceProperty( minSizePref, "max", 100 );
564 int maxSizePref = addPreference( tr( "VISU_GAUSS_PREF_MAX_SIZE" ), sizeGr,
565 LightApp_Preferences::IntSpin, "VISU",
566 "inside_point_sprite_max_size" );
567 setPreferenceProperty( maxSizePref, "min", 1 );
568 setPreferenceProperty( maxSizePref, "max", 100 );
570 int magnificationGr = addPreference( tr( "VISU_GAUSS_PREF_MAGNIFICATION_GROUP_TTL" ), insideCursorTab );
571 setPreferenceProperty( magnificationGr, "columns", 2 );
573 int magnificationPref = addPreference( tr( "VISU_GAUSS_PREF_MAGNIFICATION" ), magnificationGr,
574 LightApp_Preferences::IntSpin, "VISU",
575 "inside_point_sprite_magnification" );
576 setPreferenceProperty( magnificationPref, "min", 10 );
577 setPreferenceProperty( magnificationPref, "max", 1000 );
579 int incrementPref = addPreference( tr( "VISU_GAUSS_PREF_INCREMENT" ), magnificationGr,
580 LightApp_Preferences::DblSpin, "VISU",
581 "inside_point_sprite_increment" );
582 setPreferenceProperty( incrementPref, "min", 0.01 );
583 setPreferenceProperty( incrementPref, "max", 10 );
584 setPreferenceProperty( incrementPref, "step", 0.1 );
588 //---------------------------------------------------------------
591 createOutsideCursorPreferences()
593 int outsideCursorTab = addPreference( tr( "VISU_GAUSS_OUTSIDE_CURSOR_PREF_TAB_TTL" ) );
595 int primitiveGr = addPreference( tr( "VISU_GAUSS_PREF_PRIMITIVE_GROUP_TTL" ), outsideCursorTab );
596 setPreferenceProperty( primitiveGr, "columns", 1 );
598 int primitiveTypePref = addPreference( tr( "VISU_GAUSS_PREF_PRIMITIVE_TYPE" ), primitiveGr,
599 LightApp_Preferences::Selector, "VISU",
600 "outside_point_sprite_primitive_type" );
603 values.append( tr( "VISU_GAUSS_PREF_POINTSPRITE" ) );
604 values.append( tr( "VISU_GAUSS_PREF_OPENGLPOINT" ) );
605 values.append( tr( "VISU_GAUSS_PREF_GEOMSPHERE" ) );
606 QValueList<QVariant> indices;
610 setPreferenceProperty( primitiveTypePref, "strings", values );
611 setPreferenceProperty( primitiveTypePref, "indexes", indices );
613 int clampPref = addPreference( tr( "VISU_GAUSS_PREF_CLAMP" ), primitiveGr,
614 LightApp_Preferences::IntSpin, "VISU", "outside_point_sprite_clamp" );
615 setPreferenceProperty( clampPref, "min", 1 );
616 setPreferenceProperty( clampPref, "max", 512 );
618 addPreference( tr( "VISU_GAUSS_PREF_MAIN_TEXTURE" ), primitiveGr,
619 LightApp_Preferences::File, "VISU", "outside_point_sprite_main_texture" );
621 addPreference( tr( "VISU_GAUSS_PREF_ALPHA_TEXTURE" ), primitiveGr,
622 LightApp_Preferences::File, "VISU", "outside_point_sprite_alpha_texture" );
624 int alphaThresholdPref = addPreference( tr( "VISU_GAUSS_PREF_ALPHA_THRESHOLD" ), primitiveGr,
625 LightApp_Preferences::DblSpin, "VISU",
626 "outside_point_sprite_alpha_threshold" );
627 setPreferenceProperty( alphaThresholdPref, "min", 0.0 );
628 setPreferenceProperty( alphaThresholdPref, "max", 1.0 );
629 setPreferenceProperty( alphaThresholdPref, "step", 0.1 );
631 int resolutionPref = addPreference( tr( "VISU_GAUSS_PREF_RESOLUTION" ), primitiveGr,
632 LightApp_Preferences::IntSpin, "VISU",
633 "outside_geom_sphere_resolution" );
634 setPreferenceProperty( resolutionPref, "min", 3 );
635 setPreferenceProperty( resolutionPref, "max", 100 );
637 int faceLimitPref = addPreference( tr( "VISU_GAUSS_PREF_FACE_LIMIT" ), primitiveGr,
638 LightApp_Preferences::IntSpin, "VISU",
639 "outside_geom_sphere_face_limit" );
640 setPreferenceProperty( faceLimitPref, "min", 10 );
641 setPreferenceProperty( faceLimitPref, "max", 1000000 );
643 int sizeGr = addPreference( tr( "VISU_GAUSS_PREF_SIZE_GROUP_TTL" ), outsideCursorTab );
645 int sizePref = addPreference( tr( "VISU_GAUSS_PREF_SIZE" ), sizeGr,
646 LightApp_Preferences::IntSpin, "VISU", "outside_point_sprite_size" );
647 setPreferenceProperty( sizePref, "min", 1 );
648 setPreferenceProperty( sizePref, "max", 100 );
650 int colorGr = addPreference( tr( "VISU_GAUSS_PREF_COLOR_GROUP_TTL" ), outsideCursorTab );
651 setPreferenceProperty( colorGr, "columns", 1 );
653 addPreference( tr( "VISU_GAUSS_PREF_UNIFORM_COLOR" ), colorGr,
654 LightApp_Preferences::Bool, "VISU", "outside_point_sprite_uniform" );
656 addPreference( tr( "VISU_GAUSS_PREF_COLOR" ), colorGr,
657 LightApp_Preferences::Color, "VISU", "outside_point_sprite_color" );
661 //---------------------------------------------------------------
664 createPickingPreferences()
666 int pickingTab = addPreference( tr( "VISU_PICKING_PREF_TAB_TTL" ) );
669 int cursorGr = addPreference( tr( "VISU_PICKING_PREF_CURSOR_GROUP_TTL" ), pickingTab );
670 setPreferenceProperty( cursorGr, "columns", 1 );
672 int cursorSizePref = addPreference( tr( "VISU_PICKING_PREF_CURSOR_SIZE" ), cursorGr,
673 LightApp_Preferences::DblSpin, "VISU", "picking_cursor_size" );
674 setPreferenceProperty( cursorSizePref, "min", 0 );
675 setPreferenceProperty( cursorSizePref, "max", 1.0 );
676 setPreferenceProperty( cursorSizePref, "step", 0.1 );
678 int pyramidHeightPref = addPreference( tr( "VISU_PICKING_PREF_PYRAMID_HEIGHT" ), cursorGr,
679 LightApp_Preferences::DblSpin, "VISU", "picking_pyramid_height" );
680 setPreferenceProperty( pyramidHeightPref, "min", 1 );
681 setPreferenceProperty( pyramidHeightPref, "max", 100 );
683 /*int selectionColorPref = */
684 addPreference( tr( "VISU_PICKING_PREF_SELECTION_COLOR" ), cursorGr,
685 LightApp_Preferences::Color, "VISU", "picking_selection_color" );
688 int toleranceGr = addPreference( tr( "VISU_PICKING_PREF_TOLERANCE_GROUP_TTL" ), pickingTab );
690 int pointTolerancePref = addPreference( tr( "VISU_PICKING_PREF_POINT_SELECTION_TOLERANCE" ), toleranceGr,
691 LightApp_Preferences::DblSpin, "VISU", "picking_point_tolerance" );
692 setPreferenceProperty( pointTolerancePref, "min", 0.001 );
693 setPreferenceProperty( pointTolerancePref, "max", 10 );
694 setPreferenceProperty( pointTolerancePref, "step", 0.01 );
697 int infoWindowGr = addPreference( tr( "VISU_PICKING_PREF_INFO_WINDOW_GROUP_TTL" ), pickingTab );
698 setPreferenceProperty( infoWindowGr, "columns", 1 );
700 int transparencyPref = addPreference( tr( "VISU_PICKING_PREF_TRANSPARENCY" ), infoWindowGr,
701 LightApp_Preferences::IntSpin, "VISU", "picking_transparency" );
702 setPreferenceProperty( transparencyPref, "min", 0 );
703 setPreferenceProperty( transparencyPref, "max", 100 );
704 setPreferenceProperty( transparencyPref, "step", 10 );
706 int positionPref = addPreference( tr( "VISU_PICKING_PREF_POSITION" ), infoWindowGr,
707 LightApp_Preferences::Selector, "VISU", "picking_position" );
709 values.append( tr( "VISU_PICKING_PREF_BELOW_POINT" ) );
710 values.append( tr( "VISU_PICKING_PREF_TOP_LEFT_CORNER" ) );
711 QValueList<QVariant> indices;
714 setPreferenceProperty( positionPref, "strings", values );
715 setPreferenceProperty( positionPref, "indexes", indices );
718 int cameraGr = addPreference( tr( "VISU_PICKING_PREF_CAMERA_GROUP_TTL" ), pickingTab );
719 setPreferenceProperty( cameraGr, "columns", 1 );
721 int zoomFactorPref = addPreference( tr( "VISU_PICKING_PREF_ZOOM_FACTOR" ), cameraGr,
722 LightApp_Preferences::DblSpin, "VISU", "picking_zoom_factor" );
723 setPreferenceProperty( zoomFactorPref, "min", 0.1 );
724 setPreferenceProperty( zoomFactorPref, "max", 10.0 );
725 setPreferenceProperty( zoomFactorPref, "step", 0.1 );
727 int stepNumberPref = addPreference( tr( "VISU_PICKING_PREF_STEP_NUMBER" ), cameraGr,
728 LightApp_Preferences::IntSpin, "VISU", "picking_step_number" );
729 setPreferenceProperty( stepNumberPref, "min", 1 );
730 setPreferenceProperty( stepNumberPref, "max", 100 );
732 // Display parent mesh
733 int parentMeshGr = addPreference( tr( "VISU_PICKING_PREF_PARENT_MESH_TTL" ), pickingTab );
734 setPreferenceProperty( parentMeshGr, "columns", 1 );
736 addPreference( tr( "VISU_PICKING_PREF_DISPLAY_PARENT_MESH" ), parentMeshGr,
737 LightApp_Preferences::Bool, "VISU", "picking_display_parent_mesh" );
741 //---------------------------------------------------------------
744 createSpaceMousePreferences()
746 int mouseTab = addPreference( tr( "VISU_MOUSE_PREF_TAB_TLT" ) );
748 int mouseGr = addPreference( tr( "VISU_MOUSE_PREF_GROUP_TLT" ), mouseTab );
749 int mousePref = addPreference( tr( "VISU_MOUSE_PREF" ), mouseGr,
750 LightApp_Preferences::Selector, "VISU", "mouse_behaviour" );
752 values.append( tr( "VISU_MOUSE_PREF_STANDARD" ) );
753 values.append( tr( "VISU_MOUSE_PREF_KEYBOARD_FREE" ) );
754 QValueList<QVariant> indices;
757 setPreferenceProperty( mousePref, "strings", values );
758 setPreferenceProperty( mousePref, "indexes", indices );
760 int keybrdGr = addPreference( tr( "VISU_KEYBOARD_PREF_GROUP_TTL" ), mouseTab );
761 int keybrdPref = addPreference( tr( "VISU_KEYBOARD_PREF" ), keybrdGr,
762 LightApp_Preferences::IntSpin, "VISU", "speed_increment" );
763 setPreferenceProperty( keybrdPref, "max", 1000 );
765 int spacemouseGr = addPreference( tr( "VISU_SPACEMOUSE_PREF" ), mouseTab );
766 setPreferenceProperty( spacemouseGr, "columns", 1 );
767 int spacemousePref1 = addPreference( tr( "VISU_SPACEMOUSE_PREF_1" ), spacemouseGr,
768 LightApp_Preferences::Selector, "VISU",
769 "spacemouse_func1_btn" ); //decrease_speed_increment
770 int spacemousePref2 = addPreference( tr( "VISU_SPACEMOUSE_PREF_2" ), spacemouseGr,
771 LightApp_Preferences::Selector, "VISU",
772 "spacemouse_func2_btn" ); //increase_speed_increment
773 int spacemousePref3 = addPreference( tr( "VISU_SPACEMOUSE_PREF_3" ), spacemouseGr,
774 LightApp_Preferences::Selector, "VISU",
775 "spacemouse_func3_btn" ); //decrease_gauss_point_magnification
776 int spacemousePref4 = addPreference( tr( "VISU_SPACEMOUSE_PREF_4" ), spacemouseGr,
777 LightApp_Preferences::Selector, "VISU",
778 "spacemouse_func4_btn" ); //increase_gauss_point_magnification
779 int spacemousePref5 = addPreference( tr( "VISU_SPACEMOUSE_PREF_5" ), spacemouseGr,
780 LightApp_Preferences::Selector, "VISU",
781 "spacemouse_func5_btn" ); //dominant_combined_switch
783 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_1" ) );
784 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_2" ) );
785 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_3" ) );
786 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_4" ) );
787 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_5" ) );
788 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_6" ) );
789 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_7" ) );
790 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_8" ) );
791 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_*" ) );
792 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_10" ) );
793 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_11" ) );
803 indices.append( 9 ); // == button_*
804 indices.append( 10 );
805 indices.append( 11 );
806 setPreferenceProperty( spacemousePref1, "strings", values );
807 setPreferenceProperty( spacemousePref1, "indexes", indices );
808 setPreferenceProperty( spacemousePref2, "strings", values );
809 setPreferenceProperty( spacemousePref2, "indexes", indices );
810 setPreferenceProperty( spacemousePref3, "strings", values );
811 setPreferenceProperty( spacemousePref3, "indexes", indices );
812 setPreferenceProperty( spacemousePref4, "strings", values );
813 setPreferenceProperty( spacemousePref4, "indexes", indices );
814 setPreferenceProperty( spacemousePref5, "strings", values );
815 setPreferenceProperty( spacemousePref5, "indexes", indices );
819 //---------------------------------------------------------------
822 createRecorderPreferences()
824 int recorderTab = addPreference( tr( "VISU_RECORDER_PREF_TAB_TTL" ) );
826 int recorderGr = addPreference( tr( "VISU_RECORDER_PREF_GROUP_TTL" ), recorderTab );
827 setPreferenceProperty( recorderGr, "columns", 1 );
829 int modePref = addPreference( tr( "VISU_RECORDER_PREF_RECORDING_MODE" ), recorderGr,
830 LightApp_Preferences::Selector, "VISU", "recorder_mode" );
832 values.append( tr( "VISU_RECORDER_PREF_SKIPPED_FRAMES" ) );
833 values.append( tr( "VISU_RECORDER_PREF_ALL_DISLPAYED_FRAMES" ) );
834 QValueList<QVariant> indices;
837 setPreferenceProperty( modePref, "strings", values );
838 setPreferenceProperty( modePref, "indexes", indices );
840 int fpsPref = addPreference( tr( "VISU_RECORDER_PREF_FPS" ), recorderGr,
841 LightApp_Preferences::DblSpin, "VISU", "recorder_fps" );
842 setPreferenceProperty( fpsPref, "min", 0.1 );
843 setPreferenceProperty( fpsPref, "max", 100 );
845 int qualityPref = addPreference( tr( "VISU_RECORDER_PREF_QUALITY" ), recorderGr,
846 LightApp_Preferences::IntSpin, "VISU", "recorder_quality" );
847 setPreferenceProperty( qualityPref, "min", 1 );
848 setPreferenceProperty( qualityPref, "max", 100 );
850 addPreference( tr( "VISU_RECORDER_PREF_PROGRESSIVE" ), recorderGr,
851 LightApp_Preferences::Bool, "VISU", "recorder_progressive" );
855 //---------------------------------------------------------------
858 OnCreateGaussPoints()
860 double initialTime = vtkTimerLog::GetCPUTime();
861 CreatePrs3d<VISU::GaussPoints_i, VVTK_Viewer, VisuGUI_GaussPointsDlg, 1>(this);
862 INFOS( "VisuGUI_Module::OnCreateGaussPoints() : Gauss Points created in " <<
863 vtkTimerLog::GetCPUTime() - initialTime << " seconds" );
868 OnViewManagerAdded(SUIT_ViewManager* viewMgr)
870 QString type = viewMgr->getViewModel()->getType();
871 if ( type == VVTK_Viewer::Type() )
872 connect( viewMgr, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
873 this, SLOT( OnViewCreated( SUIT_ViewWindow* ) ) );
878 OnViewCreated(SUIT_ViewWindow* view)
880 SVTK_ViewWindow* viewWindow = dynamic_cast<SVTK_ViewWindow*>( view );
882 setProperty( viewWindow, "speed_increment" );
883 setProperty( viewWindow, "spacemouse_func1_btn" );
884 setProperty( viewWindow, "spacemouse_func2_btn" );
885 setProperty( viewWindow, "spacemouse_func3_btn" );
886 setProperty( viewWindow, "spacemouse_func4_btn" );
887 setProperty( viewWindow, "spacemouse_func5_btn" );
893 setProperty( SVTK_ViewWindow* viewWindow, const QString& pref )
898 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
899 SVTK_MainWindow* aMainWindow = viewWindow->getMainWindow();
901 if ( pref == "speed_increment" ) {
902 val = resMgr->integerValue( "VISU", pref, 10 );
903 aMainWindow->InvokeEvent( SVTK::SetSpeedIncrementEvent, &val );
905 else if ( pref == "spacemouse_func1_btn" ) {
906 val = resMgr->integerValue( "VISU", pref, 1 );
907 aMainWindow->InvokeEvent( SVTK::SetSMDecreaseSpeedEvent, &val );
909 else if ( pref == "spacemouse_func2_btn" ) {
910 val = resMgr->integerValue( "VISU", pref, 2 );
911 aMainWindow->InvokeEvent( SVTK::SetSMIncreaseSpeedEvent, &val );
913 else if ( pref == "spacemouse_func3_btn" ) {
914 val = resMgr->integerValue( "VISU", pref, 10 );
915 aMainWindow->InvokeEvent( VISU::SetSMDecreaseMagnificationEvent, &val );
917 else if ( pref == "spacemouse_func4_btn" ) {
918 val = resMgr->integerValue( "VISU", pref, 11 );
919 aMainWindow->InvokeEvent( VISU::SetSMIncreaseMagnificationEvent, &val );
921 else if ( pref == "spacemouse_func5_btn" ) {
922 val = resMgr->integerValue( "VISU", pref, 9 );
923 aMainWindow->InvokeEvent( SVTK::SetSMDominantCombinedSwitchEvent, &val );
929 setProperty( SVTK_ViewManager* vm, const QString& prop )
934 QPtrVector<SUIT_ViewWindow> windows = vm->getViews();
935 for ( int n = windows.count(), i = 0; i < n; i++ )
936 setProperty( dynamic_cast<SVTK_ViewWindow*>( windows[i] ), prop );
941 preferencesChanged( const QString& group, const QString& pref )
943 VisuGUI::preferencesChanged(group,pref);
945 if ( group == "VISU" && ( pref == "speed_increment" || pref == "spacemouse_func1_btn" ||
946 pref == "spacemouse_func2_btn" || pref == "spacemouse_func3_btn" ||
947 pref == "spacemouse_func4_btn" || pref == "spacemouse_func5_btn" ) ) {
949 // update properties of VVTK view windows
950 SUIT_ViewManager* vm = getApp()->getViewManager( VVTK_Viewer::Type(), false );
952 setProperty( dynamic_cast<SVTK_ViewManager*>( vm ), pref );
957 //---------------------------------------------------------------
960 getViewManager(const QString& theType,
961 const bool theIsCreate)
963 if (SUIT_ViewManager* aViewManager = VisuGUI::getViewManager(theType,theIsCreate))
966 if (theIsCreate && theType == VVTK_Viewer::Type())
967 return onCreateViewManager();
972 //---------------------------------------------------------------
977 Handle(SALOME_InteractiveObject) anIO;
978 if (VISU::Prs3d_i* aPrs3d = GetPrsToModify(this, &anIO)) {
979 // Create VVTK_ViewWindow, if it does not exist
980 if (VVTK_ViewWindow* aViewWindow = GetViewWindow<VVTK_Viewer>(this)) {
981 EditPrs3d<VISU::GaussPoints_i, VisuGUI_GaussPointsDlg, 1>(this, anIO, aPrs3d, aViewWindow);
987 //---------------------------------------------------------------
991 GetViewParams(VVTK_MainWindow* theViewWindow,
992 const char* theSuffix,
993 std::ostringstream& theStr)
995 vtkFloatingPointType aColor[3];
996 vtkRenderer* aRenderer = theViewWindow->getRenderer();
997 aRenderer->GetBackground(aColor);
998 Storable::DataToStream(theStr,(std::string("myColor") + theSuffix + ".R").c_str(),aColor[0]);
999 Storable::DataToStream(theStr,(std::string("myColor") + theSuffix + ".G").c_str(),aColor[1]);
1000 Storable::DataToStream(theStr,(std::string("myColor") + theSuffix + ".B").c_str(),aColor[2]);
1002 double aPosition[3];
1003 vtkCamera* aCamera = aRenderer->GetActiveCamera();
1004 aCamera->GetPosition(aPosition);
1005 Storable::DataToStream(theStr,(std::string("myPosition") + theSuffix + "[0]").c_str(),aPosition[0]);
1006 Storable::DataToStream(theStr,(std::string("myPosition") + theSuffix + "[1]").c_str(),aPosition[1]);
1007 Storable::DataToStream(theStr,(std::string("myPosition") + theSuffix + "[2]").c_str(),aPosition[2]);
1009 double aFocalPnt[3];
1010 aCamera->GetFocalPoint(aFocalPnt);
1011 Storable::DataToStream(theStr,(std::string("myFocalPnt") + theSuffix + "[0]").c_str(),aFocalPnt[0]);
1012 Storable::DataToStream(theStr,(std::string("myFocalPnt") + theSuffix + "[1]").c_str(),aFocalPnt[1]);
1013 Storable::DataToStream(theStr,(std::string("myFocalPnt") + theSuffix + "[2]").c_str(),aFocalPnt[2]);
1016 aCamera->GetViewUp(aViewUp);
1017 Storable::DataToStream(theStr,(std::string("myViewUp") + theSuffix + "[0]").c_str(),aViewUp[0]);
1018 Storable::DataToStream(theStr,(std::string("myViewUp") + theSuffix + "[1]").c_str(),aViewUp[1]);
1019 Storable::DataToStream(theStr,(std::string("myViewUp") + theSuffix + "[2]").c_str(),aViewUp[2]);
1021 vtkFloatingPointType aParallelScale = aCamera->GetParallelScale();
1022 Storable::DataToStream(theStr,(std::string("myParallelScale") + theSuffix).c_str(),aParallelScale);
1024 double aScaleFactor[3];
1025 theViewWindow->GetScale(aScaleFactor);
1026 Storable::DataToStream(theStr,(std::string("myScaleFactor") + theSuffix + "[0]").c_str(),aScaleFactor[0]);
1027 Storable::DataToStream(theStr,(std::string("myScaleFactor") + theSuffix + "[1]").c_str(),aScaleFactor[1]);
1028 Storable::DataToStream(theStr,(std::string("myScaleFactor") + theSuffix + "[2]").c_str(),aScaleFactor[2]);
1031 //---------------------------------------------------------------
1033 SetViewParams(VVTK_MainWindow* theViewWindow,
1034 const char* theSuffix,
1035 const Storable::TRestoringMap& theMap)
1037 vtkFloatingPointType aColor[3];
1038 aColor[0] = Storable::FindValue(theMap,std::string("myColor") + theSuffix + ".R").toDouble();
1039 aColor[1] = Storable::FindValue(theMap,std::string("myColor") + theSuffix + ".G").toDouble();
1040 aColor[2] = Storable::FindValue(theMap,std::string("myColor") + theSuffix + ".B").toDouble();
1041 vtkRenderer* aRenderer = theViewWindow->getRenderer();
1042 aRenderer->SetBackground(aColor);
1044 double aPosition[3];
1045 aPosition[0] = Storable::FindValue(theMap,std::string("myPosition") + theSuffix + "[0]").toDouble();
1046 aPosition[1] = Storable::FindValue(theMap,std::string("myPosition") + theSuffix + "[1]").toDouble();
1047 aPosition[2] = Storable::FindValue(theMap,std::string("myPosition") + theSuffix + "[2]").toDouble();
1048 vtkCamera* aCamera = aRenderer->GetActiveCamera();
1049 aCamera->SetPosition(aPosition);
1051 double aFocalPnt[3];
1052 aFocalPnt[0] = Storable::FindValue(theMap,std::string("myFocalPnt") + theSuffix + "[0]").toDouble();
1053 aFocalPnt[1] = Storable::FindValue(theMap,std::string("myFocalPnt") + theSuffix + "[1]").toDouble();
1054 aFocalPnt[2] = Storable::FindValue(theMap,std::string("myFocalPnt") + theSuffix + "[2]").toDouble();
1055 aCamera->SetFocalPoint(aFocalPnt);
1058 aViewUp[0] = Storable::FindValue(theMap,std::string("myViewUp") + theSuffix + "[0]").toDouble();
1059 aViewUp[1] = Storable::FindValue(theMap,std::string("myViewUp") + theSuffix + "[1]").toDouble();
1060 aViewUp[2] = Storable::FindValue(theMap,std::string("myViewUp") + theSuffix + "[2]").toDouble();
1061 aCamera->SetViewUp(aViewUp);
1063 vtkFloatingPointType aParallelScale = Storable::FindValue(theMap,std::string("myParallelScale") + theSuffix).toDouble();
1064 aCamera->SetParallelScale(aParallelScale);
1066 double aScaleFactor[3];
1067 aScaleFactor[0] = Storable::FindValue(theMap,std::string("myScaleFactor") + theSuffix + "[0]").toDouble();
1068 aScaleFactor[1] = Storable::FindValue(theMap,std::string("myScaleFactor") + theSuffix + "[1]").toDouble();
1069 aScaleFactor[2] = Storable::FindValue(theMap,std::string("myScaleFactor") + theSuffix + "[2]").toDouble();
1070 theViewWindow->SetScale(aScaleFactor);
1073 //---------------------------------------------------------------
1075 GetViewParams(VVTK_MainWindow1* theViewWindow,
1076 std::ostringstream& theStr)
1078 GetViewParams(theViewWindow,"1",theStr);
1080 VISU_WidgetCtrl* aWidgetCtrl = theViewWindow->GetWidgetCtrl();
1081 if(aWidgetCtrl->GetEnabled()){
1082 std::string aSegmentationMode;
1083 if(aWidgetCtrl->IsPlanesActive()){
1084 VISU_PlanesWidget *aPlanesWidget = aWidgetCtrl->GetPlanesWidget();
1085 vtkFloatingPointType anOrigin[3];
1086 aPlanesWidget->GetOrigin(anOrigin);
1087 Storable::DataToStream(theStr,"myCursorOrigin[0]",anOrigin[0]);
1088 Storable::DataToStream(theStr,"myCursorOrigin[1]",anOrigin[1]);
1089 Storable::DataToStream(theStr,"myCursorOrigin[2]",anOrigin[2]);
1091 vtkFloatingPointType aNormal[3];
1092 aPlanesWidget->GetNormal(aNormal);
1093 Storable::DataToStream(theStr,"myCursorNormal[0]",aNormal[0]);
1094 Storable::DataToStream(theStr,"myCursorNormal[1]",aNormal[1]);
1095 Storable::DataToStream(theStr,"myCursorNormal[2]",aNormal[2]);
1097 vtkFloatingPointType aDepth = aPlanesWidget->Distance();
1098 Storable::DataToStream(theStr,"myCursorDepth",aDepth);
1100 aSegmentationMode = "Planes";
1101 }else if(aWidgetCtrl->IsSphereActive()){
1102 VISU_SphereWidget *aSphereWidget = aWidgetCtrl->GetSphereWidget();
1103 vtkFloatingPointType aCenter[3];
1104 aSphereWidget->GetCenter(aCenter);
1105 Storable::DataToStream(theStr,"mySphereCursorCenter[0]",aCenter[0]);
1106 Storable::DataToStream(theStr,"mySphereCursorCenter[1]",aCenter[1]);
1107 Storable::DataToStream(theStr,"mySphereCursorCenter[2]",aCenter[2]);
1109 vtkFloatingPointType aRadius = aSphereWidget->GetRadius();
1110 Storable::DataToStream(theStr,"mySphereCursorRaduis",aRadius);
1112 aSegmentationMode = "Sphere";
1115 Storable::DataToStream(theStr,"mySegmentationMode",aSegmentationMode.c_str());
1119 //---------------------------------------------------------------
1121 SetViewParams(VVTK_MainWindow1* theViewWindow,
1122 const Storable::TRestoringMap& theMap)
1124 SetViewParams(theViewWindow,"1",theMap);
1128 //---------------------------------------------------------------
1130 GetViewParams(VVTK_MainWindow2* theViewWindow,
1131 std::ostringstream& theStr)
1133 GetViewParams(theViewWindow,"2",theStr);
1137 SetViewParams(VVTK_MainWindow2* theViewWindow,
1138 const Storable::TRestoringMap& theMap)
1140 SetViewParams(theViewWindow,"2",theMap);
1144 //---------------------------------------------------------------
1146 GetViewParams(VVTK_ViewWindow* theViewWindow)
1148 std::ostringstream aStream;
1150 Storable::DataToStream(aStream,"myComment","GAUSSVIEW");
1152 SVTK_Selector* aSelector = theViewWindow->GetSelector();
1153 Selection_Mode aSelectionMode = aSelector->SelectionMode();
1154 Storable::DataToStream(aStream,"mySelectionMode",aSelectionMode);
1156 GetViewParams(theViewWindow->getMainWindow1(),aStream);
1157 GetViewParams(theViewWindow->getMainWindow2(),aStream);
1159 return aStream.str();
1162 //---------------------------------------------------------------
1170 myIsSelected(false),
1176 typedef std::map<std::string,TSelection> TVisibleEntries;
1178 struct TGetVisibleEntries
1180 TVisibleEntries& myVisibleEntries;
1182 TGetVisibleEntries(TVisibleEntries& theVisibleEntries):
1183 myVisibleEntries(theVisibleEntries)
1187 operator()(VISU_GaussPtsAct* theActor)
1189 if(theActor->GetVisibility()){
1190 const Handle(SALOME_InteractiveObject)& anIO = theActor->getIO();
1191 myVisibleEntries.insert(TVisibleEntries::value_type(anIO->getEntry(),TSelection()));
1197 GetGaussPointsSelection(VVTK_ViewWindow* theViewWindow,
1198 TVisibleEntries& theVisibleEntries)
1200 // First find all visible Gauss Points presentations
1201 vtkRenderer* aRenderer = theViewWindow->getRenderer();
1202 vtkActorCollection* anActors = aRenderer->GetActors();
1203 TGetVisibleEntries aGetVisibleEntries(theVisibleEntries);
1204 SVTK::ForEach<VISU_GaussPtsAct>(anActors,
1205 aGetVisibleEntries);
1207 // Next, find the sub-ids for the visible Gauss Points presentations
1208 SVTK_Selector* aSelector = theViewWindow->GetSelector();
1209 const SALOME_ListIO& aListIO = aSelector->StoredIObjects();
1210 SALOME_ListIteratorOfListIO anIter(aListIO);
1211 for(; anIter.More(); anIter.Next()){
1212 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
1213 std::string anEntry = anIO->getEntry();
1214 TVisibleEntries::iterator anEntriesIter = theVisibleEntries.find(anEntry);
1215 if(anEntriesIter != theVisibleEntries.end()){
1216 TSelection& aSelection = anEntriesIter->second;
1217 aSelection.myIsSelected = true;
1218 TColStd_IndexedMapOfInteger anIndexes;
1219 aSelector->GetIndex(anIO,anIndexes);
1220 if(anIndexes.Extent() > 0){
1221 aSelection.myHasSubId = true;
1222 aSelection.mySubId = anIndexes(1);
1229 //---------------------------------------------------------------
1232 CreateReference(_PTR(Study) theStudyDocument,
1233 _PTR(StudyBuilder) theStudyBuilder,
1234 _PTR(SObject) theFatherSObject,
1235 const string& theRefEntry,
1236 const TSelection& theSelection)
1238 _PTR(SObject) aNewObj = theStudyBuilder->NewObject(theFatherSObject);
1239 _PTR(SObject) aRefSObj = theStudyDocument->FindObjectID(theRefEntry);
1240 theStudyBuilder->Addreference(aNewObj,aRefSObj);
1242 std::ostringstream aStream;
1243 Storable::DataToStream(aStream,"myIsSelected",theSelection.myIsSelected);
1244 Storable::DataToStream(aStream,"myHasSubId",theSelection.myHasSubId);
1245 Storable::DataToStream(aStream,"mySubId",theSelection.mySubId);
1247 _PTR(GenericAttribute) anAttr;
1248 anAttr = theStudyBuilder->FindOrCreateAttribute(aNewObj,"AttributeComment");
1249 _PTR(AttributeComment) aComment(anAttr);
1250 aComment->SetValue(aStream.str());
1254 //---------------------------------------------------------------
1256 SetGaussPointsSelection(VisuGUI* theModule,
1257 VVTK_ViewWindow* theViewWindow,
1258 _PTR(Study) theCStudy,
1259 _PTR(SObject) theSObject)
1261 SVTK_Selector* aSelector = theViewWindow->GetSelector();
1262 aSelector->ClearIObjects();
1264 bool anIsFirst = true;
1265 _PTR(ChildIterator) aChildIter = theCStudy->NewChildIterator(theSObject);
1266 for (; aChildIter->More(); aChildIter->Next()) {
1267 _PTR(SObject) aChildSObject = aChildIter->Value();
1268 _PTR(SObject) aSObject;
1269 if(aChildSObject->ReferencedObject(aSObject)){
1270 CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObject);
1271 PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
1272 if(VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in())){
1274 VISU::UpdateViewer(theModule, aPrs3d, /*disp_only = */anIsFirst, /*highlight = */false);
1277 // To update selection
1278 _PTR(GenericAttribute) anAttr;
1279 if(aChildSObject->FindAttribute(anAttr,"AttributeComment")){
1280 _PTR(AttributeComment) aComment(anAttr);
1282 QString aStream(aComment->Value().c_str());
1283 Storable::TRestoringMap aMap;
1284 Storable::StrToMap(aStream,aMap);
1286 bool anIsSelected = Storable::FindValue(aMap,"myIsSelected").toInt();
1287 bool aHasSubId = Storable::FindValue(aMap,"myHasSubId").toInt();
1288 int aSubId = Storable::FindValue(aMap,"mySubId").toInt();
1291 std::string anEntry = aSObject->GetID();
1292 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(anEntry.c_str(),"");
1293 aSelector->AddIObject(anIO);
1295 aSelector->AddOrRemoveIndex(anIO,aSubId,false);
1302 aSelector->EndPickCallback(); // To invoke selection changed signal
1306 //---------------------------------------------------------------
1308 OnStoreConfiguration(SalomeApp_Module* theModule,
1311 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1312 if (CheckLock(aCStudy,GetDesktop(theModule)))
1315 LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
1317 SUIT_ViewManager* aViewManager = theModule->getApp()->activeViewManager();
1318 if(aViewManager->getType() == VVTK_Viewer::Type()){
1319 SUIT_ViewWindow* aWindow = aViewManager->getActiveView();
1320 VVTK_ViewWindow* aViewWindow = dynamic_cast<VVTK_ViewWindow*>(aWindow);
1322 SUIT_Study* aSStudy = aViewManager->study();
1323 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy);
1324 _PTR(Study) aCStudy = aStudy->studyDS();
1325 _PTR(StudyBuilder) aStudyBuilder = aCStudy->NewBuilder();
1327 std::string anEntry;
1328 std::string aValue = GetViewParams(aViewWindow);
1331 _PTR(SComponent) aSComponent = ClientFindOrCreateVisuComponent(aCStudy);
1333 static int myNbConfigs = 0;
1334 std::string aName = VISU::GenerateName("Config.", ++myNbConfigs).latin1();
1336 std::string aSComponentEntry = aSComponent->GetID();
1337 anEntry = CreateAttributes(aCStudy,
1338 aSComponentEntry.c_str(),
1345 SALOME_ListIO aListIO;
1346 aSelectionMgr->selectedObjects(aListIO);
1347 SALOME_ListIteratorOfListIO aListIter( aListIO );
1348 for(; aListIter.More(); aListIter.Next()){
1349 Handle(SALOME_InteractiveObject) anIO = aListIter.Value();
1350 _PTR(SObject) aSObject = aCStudy->FindObjectID(anIO->getEntry());
1351 _PTR(GenericAttribute) anAttr;
1352 if(aSObject->FindAttribute(anAttr,"AttributeComment")){
1353 _PTR(AttributeComment) aComment(anAttr);
1354 std::string aCommentValue(aComment->Value());
1355 if(aCommentValue.compare("myComment=GAUSSVIEW") >= 0){
1356 aComment->SetValue(aValue.c_str());
1357 anEntry = aSObject->GetID();
1359 _PTR(ChildIterator) aChildIter = aCStudy->NewChildIterator(aSObject);
1360 for (; aChildIter->More(); aChildIter->Next()) {
1361 _PTR(SObject) aChildSObject = aChildIter->Value();
1362 aStudyBuilder->RemoveObject(aChildSObject);
1371 TVisibleEntries aVisibleEntries;
1372 GetGaussPointsSelection(aViewWindow,
1375 _PTR(SObject) aSObject = aCStudy->FindObjectID(anEntry);
1376 _PTR(StudyBuilder) aStudyBuilder = aCStudy->NewBuilder();
1377 TVisibleEntries::const_iterator anIter = aVisibleEntries.begin();
1378 for(; anIter != aVisibleEntries.end(); anIter++){
1379 const std::string& anEntry = anIter->first;
1380 const TSelection& aSelection = anIter->second;
1382 CreateReference(aCStudy,
1389 //UpdateObjBrowser(theModule,true,aSObject);
1390 UpdateObjBrowser(theModule,true);
1396 //---------------------------------------------------------------
1397 template<class TMainWindow>
1399 SetMainWindowParams(VisuGUI* theModule,
1400 _PTR(SObject) theSObject,
1401 VVTK_ViewWindow* theViewWindow,
1402 TMainWindow* theMainWindow)
1404 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1406 _PTR(GenericAttribute) anAttr;
1407 if(theSObject->FindAttribute(anAttr,"AttributeComment")){
1408 _PTR(AttributeComment) aComment(anAttr);
1409 QString aStream(aComment->Value().c_str());
1410 Storable::TRestoringMap aMap;
1411 Storable::StrToMap(aStream,aMap);
1412 SetViewParams(theMainWindow,aMap);
1418 //---------------------------------------------------------------
1421 OnSaveConfiguration()
1423 ::OnStoreConfiguration(this,true);
1427 //---------------------------------------------------------------
1430 OnOverwriteConfiguration()
1432 ::OnStoreConfiguration(this,false);
1436 //---------------------------------------------------------------
1439 OnRestoreConfiguration()
1441 LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
1443 SALOME_ListIO aListIO;
1444 aSelectionMgr->selectedObjects(aListIO);
1445 if(aListIO.Extent() > 1)
1448 if(SUIT_ViewManager* aViewManager = getViewManager(VVTK_Viewer::Type(),true)){
1449 const Handle(SALOME_InteractiveObject)& anIO = aListIO.First();
1450 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this));
1451 _PTR(SObject) aSObject = aCStudy->FindObjectID(anIO->getEntry());
1452 myConfigSObject = aSObject;
1453 _PTR(GenericAttribute) anAttr;
1454 if(aSObject->FindAttribute(anAttr,"AttributeComment")){
1455 _PTR(AttributeComment) aComment(anAttr);
1456 QString aStream(aComment->Value().c_str());
1457 Storable::TRestoringMap aMap;
1458 Storable::StrToMap(aStream,aMap);
1459 SUIT_ViewWindow* aWindow = aViewManager->getActiveView();
1460 VVTK_ViewWindow* aViewWindow = dynamic_cast<VVTK_ViewWindow*>(aWindow);
1462 Selection_Mode aSelectionMode = Storable::FindValue(aMap,"mySelectionMode").toInt();
1463 SVTK_Selector* aSelector = aViewWindow->GetSelector();
1464 aSelector->SetSelectionMode(aSelectionMode);
1466 SetGaussPointsSelection(this,aViewWindow,aCStudy,aSObject);
1468 std::string aSegmentationMode;
1469 if(VVTK_MainWindow1* aMainWindow = aViewWindow->getMainWindow1()){
1470 aMainWindow->SetPlanesSegementation(false);
1471 aMainWindow->SetSphereSegementation(false);
1472 VISU_WidgetCtrl* aWidgetCtrl = aMainWindow->GetWidgetCtrl();
1473 aSegmentationMode = Storable::FindValue(aMap,"mySegmentationMode").latin1();
1475 if(aSegmentationMode == "Planes"){
1476 VISU_PlanesWidget *aPlanesWidget = aWidgetCtrl->GetPlanesWidget();
1477 vtkFloatingPointType anOrigin[3];
1478 anOrigin[0] = Storable::FindValue(aMap,"myCursorOrigin[0]").toDouble();
1479 anOrigin[1] = Storable::FindValue(aMap,"myCursorOrigin[1]").toDouble();
1480 anOrigin[2] = Storable::FindValue(aMap,"myCursorOrigin[2]").toDouble();
1481 aPlanesWidget->SetOrigin(anOrigin);
1483 vtkFloatingPointType aNormal[3];
1484 aNormal[0] = Storable::FindValue(aMap,"myCursorNormal[0]").toDouble();
1485 aNormal[1] = Storable::FindValue(aMap,"myCursorNormal[1]").toDouble();
1486 aNormal[2] = Storable::FindValue(aMap,"myCursorNormal[2]").toDouble();
1487 aPlanesWidget->SetNormal(aNormal);
1489 vtkFloatingPointType aDepth = Storable::FindValue(aMap,"myCursorDepth").toDouble();
1490 aPlanesWidget->SetDistance(aDepth);
1492 aMainWindow->SetPlanesSegementation(true);
1493 }else if(aSegmentationMode == "Sphere"){
1494 VISU_SphereWidget *aSphereWidget = aWidgetCtrl->GetSphereWidget();
1495 vtkFloatingPointType aCenter[3];
1496 aCenter[0] = Storable::FindValue(aMap,"mySphereCursorCenter[0]").toDouble();
1497 aCenter[1] = Storable::FindValue(aMap,"mySphereCursorCenter[1]").toDouble();
1498 aCenter[2] = Storable::FindValue(aMap,"mySphereCursorCenter[2]").toDouble();
1499 aSphereWidget->SetCenter(aCenter);
1501 vtkFloatingPointType aRadius = Storable::FindValue(aMap,"mySphereCursorRaduis").toDouble();
1502 aSphereWidget->SetRadius(aRadius);
1504 aMainWindow->SetSphereSegementation(true);
1508 if(VVTK_MainWindow1* aMainWindow = aViewWindow->getMainWindow1()){
1509 SVTK_RenderWindowInteractor* anInteractor = aMainWindow->GetInteractor();
1510 if(anInteractor->isVisible()){
1511 SetMainWindowParams(this,myConfigSObject,aViewWindow,aMainWindow);
1513 anInteractor->installEventFilter(this);
1516 if(aSegmentationMode != ""){
1517 if(VVTK_MainWindow2* aMainWindow = aViewWindow->getMainWindow2()){
1518 SVTK_RenderWindowInteractor* anInteractor = aMainWindow->GetInteractor();
1519 if(anInteractor->isVisible())
1520 SetMainWindowParams(this,myConfigSObject,aViewWindow,aMainWindow);
1522 anInteractor->installEventFilter(this);
1526 SetGaussPointsSelection(this,aViewWindow,aCStudy,aSObject);
1532 //---------------------------------------------------------------
1535 eventFilter( QObject * theWatched, QEvent * theEvent )
1537 bool aRet = VisuGUI::eventFilter(theWatched,theEvent);
1538 if(theEvent->type() == QEvent::Show){
1539 if(SUIT_ViewManager* aViewManager = getViewManager(VVTK_Viewer::Type(),false)){
1540 SUIT_ViewWindow* aWindow = aViewManager->getActiveView();
1541 VVTK_ViewWindow* aViewWindow = dynamic_cast<VVTK_ViewWindow*>(aWindow);
1542 if(VVTK_MainWindow1* aMainWindow = aViewWindow->getMainWindow1()){
1543 SVTK_RenderWindowInteractor* anInteractor = aMainWindow->GetInteractor();
1544 if(theWatched == anInteractor){
1545 SetMainWindowParams(this,myConfigSObject,aViewWindow,aMainWindow);
1546 anInteractor->removeEventFilter(this);
1549 if(VVTK_MainWindow2* aMainWindow = aViewWindow->getMainWindow2()){
1550 SVTK_RenderWindowInteractor* anInteractor = aMainWindow->GetInteractor();
1551 if(theWatched == aMainWindow->GetInteractor()){
1552 SetMainWindowParams(this,myConfigSObject,aViewWindow,aMainWindow);
1553 anInteractor->removeEventFilter(this);
1562 const char gSeparator = '_'; // character used to separate parameter names
1563 const char gDigitsSep = ':'; // character used to separate numeric parameter values (color = r:g:b)
1565 * \brief Virtual public
1567 * This method is called just before the study document is saved, so the module has a possibility
1568 * to store visual parameters in AttributeParameter attribue(s)
1570 void VisuGUI_Module::storeVisualParameters(int savePoint)
1572 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
1573 if( !study || !study->studyDS() )
1575 _PTR(Study) studyDS = study->studyDS();
1576 _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative", moduleName().latin1(), savePoint);
1577 _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
1579 // viewers counters are used for storing view_numbers in IParameters
1580 int svtkViewers( 0 ), vvtkViewers( 0 ), plotViewers( 0 );
1582 // componentName is used for encoding of entries when storing them in IParameters
1583 _PTR(SComponent) visuEng = ClientFindOrCreateVisuComponent( studyDS );
1584 std::string componentName = visuEng->ComponentDataType();
1586 QPtrList<SUIT_ViewManager> lst;
1588 // saving VVTK viewer parameters. VVTK (Gauss Viewers) are NOT created by SalomeApp since
1589 // VVTK is declared in VISU, so here we store VVTK view window parameters.
1590 // VisuGUI_Module::restoreVisualParameters() creates VVTK_Views and restores its parameters.
1591 ip->setProperty( "ActiveGaussViewer", "-1" );
1592 getApp()->viewManagers( VVTK_Viewer::Type(), lst );
1593 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it ) {
1594 SUIT_ViewManager* vman = it.current();
1595 if ( SUIT_ViewWindow* vwin = vman->getActiveView() ) {
1596 // using predefined string "GaussViewer" as "entry".. it's a hardcoded "workaround".
1597 // gauss viewer parameters are retrieved using this "entry" string.
1598 // name of parameter = caption of gauss ViewWindow
1599 // value of parameter = ViewWindow's visual parameters
1600 ip->setParameter( "GaussViewer", vwin->caption().latin1(), vwin->getVisualParameters().latin1() );
1602 if ( application()->desktop()->activeWindow() == vwin )
1603 ip->setProperty( "ActiveGaussViewer", QString::number( vvtkViewers ).latin1() );
1608 // VISU module opens one SVTK viewer in activateModule(). This causes a bug in save-restore visual
1609 // parameters: it no SVTK view was saved, we need NOT any SVTK on restore. Here we store if any is open..
1612 getApp()->viewManagers( SVTK_Viewer::Type(), lst );
1613 ip->setProperty( "VtkViewersCount", QString::number( lst.count() ).latin1() );
1616 // main cycle to store parameters of displayed objects
1618 getApp()->viewManagers( lst );
1619 vvtkViewers = svtkViewers = plotViewers = 0;
1620 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it ) {
1621 SUIT_ViewManager* vman = it.current();
1622 QString vType = vman->getType();
1623 int* viewsCounter = vType == SVTK_Viewer::Type() ? &svtkViewers :
1624 vType == VVTK_Viewer::Type() ? &vvtkViewers :
1625 vType == SPlot2d_Viewer::Type() ? &plotViewers : 0;
1627 // saving VTK actors' properties
1628 if ( vType == SVTK_Viewer::Type() || // processing SVTK and VVTK viewers in the same
1629 vType == VVTK_Viewer::Type() ) { // way (VVTK_ViewWindow inherits SVTK_ViewWindow)
1631 QPtrVector<SUIT_ViewWindow> views = vman->getViews();
1632 for ( int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++ ) {
1633 if ( SVTK_ViewWindow* vtkView = dynamic_cast<SVTK_ViewWindow*>( views[i] ) ) {
1634 vtkActorCollection* allActors = vtkView->getRenderer()->GetActors();
1635 allActors->InitTraversal();
1636 while ( vtkActor* actor = allActors->GetNextActor() ) {
1637 if ( actor->GetVisibility() ) { // store only visible actors
1638 if ( VISU_Actor* vActor = VISU_Actor::SafeDownCast( actor ) ) {
1639 if ( vActor->hasIO() ) { // actor corresponds to existing obj
1641 Handle(SALOME_InteractiveObject) io = vActor->getIO();
1642 // entry is "ecoded" = it does NOT contain component adress, since it is a
1643 // subject to change on next component loading
1644 std::string entry = ip->encodeEntry( io->getEntry(), componentName );
1646 std::string param, vtkParam = vType.latin1(); vtkParam += gSeparator;
1647 vtkParam += QString::number( *viewsCounter ).latin1(); vtkParam += gSeparator;
1649 param = vtkParam + "Visibility";
1650 ip->setParameter( entry, param, "On" );
1651 param = vtkParam + "Name";
1652 ip->setParameter( entry, param, vActor->getName() );
1653 param = vtkParam + "RepresentationMode";
1654 ip->setParameter( entry, param, QString::number( vActor->GetRepresentation() ).latin1() );
1655 param = vtkParam + "Opacity";
1656 ip->setParameter( entry, param, QString::number( vActor->GetOpacity() ).latin1() );
1657 vtkFloatingPointType r, g, b;
1658 vActor->GetColor(r, g, b);
1659 QString colorStr = QString::number( r ); colorStr += gDigitsSep;
1660 colorStr += QString::number( g ); colorStr += gDigitsSep;
1661 colorStr += QString::number( b );
1662 param = vtkParam + "Color";
1663 ip->setParameter( entry, param, colorStr.latin1() );
1664 param = vtkParam + "LineWidth";
1665 ip->setParameter( entry, param, QString::number( vActor->GetLineWidth() ).latin1() );
1666 if ( vActor->IsShrunkable() && vActor->IsShrunk() ) {
1667 param = vtkParam + "ShrinkMode";
1668 ip->setParameter( entry, param, "On" );
1669 param = vtkParam + "ShrinkFactor";
1670 ip->setParameter( entry, param, QString::number( vActor->GetShrinkFactor() ).latin1() );
1672 VISU_ScalarMapAct* scalarMapActor = dynamic_cast<VISU_ScalarMapAct*>( vActor );
1673 if ( scalarMapActor && scalarMapActor->IsShading() ) {
1674 param = vtkParam + "Shading";
1675 ip->setParameter( entry, param, "On" );
1677 if ( const VISU::Prs3d_i* vPrs = vActor->GetPrs3d() ) {
1678 param = vtkParam + "ClippingPlane";
1679 int nPlanes = vPrs->GetNumberOfClippingPlanes();
1681 ip->setParameter( entry, param, "Off" );
1682 for ( int p = 0; p < nPlanes; p++ ) {
1683 vtkPlane* plane = vPrs->GetClippingPlane( p );
1684 vtkFloatingPointType normal[3], origin[3];
1685 plane->GetNormal( normal );
1686 plane->GetOrigin( origin );
1687 std::string planeValue = QString::number( normal[0] ).latin1(); planeValue += gDigitsSep;
1688 planeValue += QString::number( normal[1] ).latin1(); planeValue += gDigitsSep;
1689 planeValue += QString::number( normal[2] ).latin1(); planeValue += gDigitsSep;
1690 planeValue += QString::number( origin[0] ).latin1(); planeValue += gDigitsSep;
1691 planeValue += QString::number( origin[1] ).latin1(); planeValue += gDigitsSep;
1692 planeValue += QString::number( origin[2] ).latin1();
1693 param = QString( "%1ClippingPlane_%2" ).arg( vtkParam.c_str() ).arg( p+1 ).latin1();
1694 ip->setParameter( entry, param, planeValue );
1699 } // salome_actor successfull downcast
1701 } // end of ..while.. actors traversal
1705 } // if ( SVTK view model )
1706 else if ( vType == SPlot2d_Viewer::Type() ) { // processing Plot2d viewers
1707 QPtrVector<SUIT_ViewWindow> views = vman->getViews();
1708 for ( int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++ ) {
1709 if ( Plot2d_ViewWindow* plotView = dynamic_cast<Plot2d_ViewWindow*>( views[i] ) ) {
1710 Plot2d_ViewFrame* plotVF = plotView->getViewFrame();
1711 QPtrList<Plot2d_Curve> curves;
1712 plotVF->getCurves( curves );
1714 Plot2d_Curve* curve;
1715 for ( curve = curves.first(); curve; curve = curves.next() ) {
1716 if ( SPlot2d_Curve* sCurve = dynamic_cast<SPlot2d_Curve*>( curve ) ) {
1717 if ( sCurve->hasIO() ) {
1719 Handle(SALOME_InteractiveObject) io = sCurve->getIO();
1720 // entry is "ecoded" = it does NOT contain component adress, since it is a
1721 // subject to change on next component loading
1722 std::string entry = ip->encodeEntry( io->getEntry(), componentName );
1724 std::string param, plotParam = vType.latin1(); plotParam += gSeparator;
1725 plotParam += QString::number( *viewsCounter ).latin1(); plotParam += gSeparator;
1727 param = plotParam + "Visibility";
1728 ip->setParameter( entry, param, "On" );
1732 } // if ( plotView )
1735 } // if ( SPlot2d view model )
1739 // returns VISU_Actor with IO with given entry
1740 VISU_Actor* getActor( const QString& entry, SVTK_ViewWindow* vtkView )
1742 if ( vtkView && !entry.isEmpty() ) {
1743 vtkActorCollection* allActors = vtkView->getRenderer()->GetActors();
1744 allActors->InitTraversal();
1745 while ( vtkActor* actor = allActors->GetNextActor() ) {
1746 if ( VISU_Actor* vActor = VISU_Actor::SafeDownCast( actor ) ) {
1747 if ( vActor->hasIO() ) { // actor corresponds to existing obj
1748 Handle(SALOME_InteractiveObject) io = vActor->getIO();
1749 if ( entry == io->getEntry() )
1758 const int ViewerType = 0;
1759 const int ViewIndex = 1;
1760 const int ParamName = 2;
1761 // visual parameters are stored in strings as follows:
1762 // ViewerType_ViewNumber_ParamName. '_' is used as separator and should not be used in
1763 // viewer type or parameter names
1765 // return viewer type substring from parameter name
1766 std::string getParam( const std::string& paramName, const int index )
1768 QStringList lst = QStringList::split( gSeparator, QString( paramName.c_str() ) );
1769 if ( !lst.isEmpty() && index < lst.size() )
1770 return lst[index].latin1();
1776 * \brief Virtual public
1778 * This method is called after the study document is opened, so the module has a possibility to restore
1781 void VisuGUI_Module::restoreVisualParameters(int savePoint)
1783 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
1784 if( !study || !study->studyDS() )
1786 _PTR(Study) studyDS = study->studyDS();
1787 _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative", moduleName().latin1(), savePoint);
1788 _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
1790 // actors are stored in a map after displaying of them for quicker access in future
1791 QMap<QString, QMap<QString, VISU_Actor*> > vtkActors; // map: entry to map: ViewType_<ID> to actor (SVTK/VVTK)
1793 std::vector<std::string> entries = ip->getEntries();
1795 for ( std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt ) {
1797 std::vector<std::string> paramNames = ip->getAllParameterNames( *entIt );
1798 std::vector<std::string> paramValues = ip->getAllParameterValues( *entIt );
1799 std::vector<std::string>::iterator namesIt = paramNames.begin();
1800 std::vector<std::string>::iterator valuesIt = paramValues.begin();
1802 if ( *entIt == "GaussViewer" ) {
1803 // parameter names are view window's captions, values - visual parameters.
1804 for ( ; namesIt != paramNames.end(); ++namesIt, ++valuesIt ) {
1805 SUIT_ViewManager* vman = onCreateViewManager();
1806 SUIT_ViewWindow* vwin = vman->getActiveView();
1807 vwin->setCaption( (*namesIt).c_str() );
1809 // wait untill the window is really shown. This step fixes MANY bugs..
1810 while ( !vwin->isVisible() )
1811 qApp->processEvents();
1813 vwin->setVisualParameters( (*valuesIt).c_str() );
1815 continue; // skip to next entry
1818 // entry is a normal entry - it should be "decoded" (setting base adress of component)
1819 QString entry( ip->decodeEntry( *entIt ).c_str() );
1821 //SRN: Added a check that the entry corresponds to Standard_Real object in the Study
1822 // as the object may be deleted or modified after the visual state is saved.
1823 _PTR(SObject) so = studyDS->FindObjectID(entry.latin1());
1824 if(!so) continue; //Skip the not existent entry
1826 for ( ; namesIt != paramNames.end(); ++namesIt, ++valuesIt ) {
1827 std::string viewerType = ::getParam( *namesIt, ViewerType );
1829 std::string paramName = ::getParam( *namesIt, ParamName );
1831 std::string viewIndexStr = ::getParam( *namesIt, ViewIndex );
1832 int viewIndex = QString( viewIndexStr.c_str() ).toUInt( &ok );
1833 if ( !ok ) // bad conversion of view index to integer
1836 // cout << " -- " << viewerType << ": entry = " << entry.latin1() << ", paramName = " << paramName << endl;
1838 if ( viewerType == SVTK_Viewer::Type().latin1() ||
1839 viewerType == VVTK_Viewer::Type().latin1() ) {
1841 // used as inner map key for locating the actor.
1842 QString viewerTypeIndex = QString( viewerType.c_str() ) + QString::number( viewIndex );
1844 if ( paramName == "Visibility" && displayer() ) {
1845 // if VVTK, then we must create viewer first, because
1847 QPtrList<SUIT_ViewManager> lst;
1848 getApp()->viewManagers( viewerType.c_str(), lst );
1850 // SVTK/VVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
1851 if ( viewIndex >= 0 && viewIndex < lst.count() ) {
1852 SUIT_ViewManager* vman = lst.at( viewIndex );
1853 SUIT_ViewModel* vmodel = vman->getViewModel();
1854 // both SVTK and VVTK view models can be casted to SALOME_View
1855 displayer()->Display( entry, true, dynamic_cast<SALOME_View*>( vmodel ) );
1857 // store displayed actor in a temporary map for quicker access later when restoring other parameters
1858 SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
1859 QMap<QString, VISU_Actor*> viewActorMap;
1860 if ( vtkActors.contains( entry ) )
1861 viewActorMap = vtkActors[ entry ];
1862 viewActorMap[ viewerTypeIndex ] = getActor( entry, vtkView );
1863 vtkActors[ entry ] = viewActorMap;
1866 else { // the rest properties "work" with VISU_Actor, so we initialize it at first
1867 VISU_Actor* vActor = 0;
1868 if ( vtkActors.contains( entry ) ) {
1869 QMap<QString, VISU_Actor*> viewActorMap = vtkActors[ entry ];
1870 if ( viewActorMap.contains( viewerTypeIndex ) )
1871 vActor = viewActorMap[ viewerTypeIndex ];
1876 QString val( (*valuesIt).c_str() );
1878 if ( paramName == "Name" )
1879 vActor->setName( val.latin1() );
1881 else if ( paramName == "RepresentationMode" )
1882 vActor->SetRepresentation( val.toInt() );
1884 else if ( paramName == "Opacity" )
1885 vActor->SetOpacity( val.toFloat() );
1887 else if ( paramName == "Color" ) {
1888 QStringList colors = QStringList::split( gDigitsSep, val );
1889 if ( colors.count() == 3 )
1890 vActor->SetColor( colors[0].toFloat(), colors[1].toFloat(), colors[2].toFloat() );
1893 else if ( paramName == "LineWidth" )
1894 vActor->SetLineWidth( val.toFloat() );
1896 else if ( paramName == "ShrinkMode" ) {
1897 vActor->SetShrinkable( true );
1898 vActor->SetShrink();
1901 else if ( paramName == "ShrunkFactor" )
1902 vActor->SetShrinkFactor( val.toFloat() );
1904 else if ( paramName == "Shading" ) {
1905 if ( VISU_ScalarMapAct* scalarMapActor = dynamic_cast<VISU_ScalarMapAct*>( vActor ) )
1906 scalarMapActor->SetShading();
1909 else if ( paramName.find( "ClippingPlane" ) != std::string::npos ) {
1910 VISU::Prs3d_i* prs = vActor->GetPrs3d();
1914 prs->RemoveAllClippingPlanes();
1915 if ( val != "Off" ) {
1916 QStringList vals = QStringList::split( gDigitsSep, val );
1917 if ( vals.count() == 6 ) { // format check: 6 float values
1918 vtkFloatingPointType normal[3], origin[3];
1919 for (int x = 0; x < 3; x++ ) {
1920 normal[x] = vals[x].toFloat();
1921 origin[x] = vals[x+3].toFloat();
1923 OrientedPlane* plane = OrientedPlane::New();
1924 plane->SetNormal( normal );
1925 plane->SetOrigin( origin );
1926 prs->AddClippingPlane( plane );
1934 else if ( viewerType == SPlot2d_Viewer::Type().latin1() ) {
1936 if ( paramName == "Visibility" && displayer() ) {
1937 QPtrList<SUIT_ViewManager> lst;
1938 getApp()->viewManagers( viewerType.c_str(), lst );
1940 if ( viewIndex >= 0 && viewIndex < lst.count() ) {
1941 SUIT_ViewManager* vman = lst.at( viewIndex );
1942 SUIT_ViewModel* vmodel = vman->getViewModel();
1943 // SVTK and VVTK view models can be casted to SALOME_View
1944 displayer()->Display( entry, true, dynamic_cast<SALOME_View*>( vmodel ) );
1950 } // for names/parameters iterator
1951 } // for entries iterator
1953 // [ update all SVTK/VVTK/Plot2D views
1954 QPtrList<SUIT_ViewManager> lst;
1955 getApp()->viewManagers( lst );
1956 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it ) {
1957 SUIT_ViewManager* vman = it.current();
1958 SUIT_ViewModel* vmodel = vman->getViewModel();
1961 if ( vmodel->getType() == SVTK_Viewer::Type() || // processing SVTK and VVTK viewers
1962 vmodel->getType() == VVTK_Viewer::Type() ) { // in the same way
1963 SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
1964 vtkView->getRenderer()->ResetCameraClippingRange();
1967 else if ( vmodel->getType() == SPlot2d_Viewer::Type().latin1() ) {
1968 Plot2d_ViewWindow* plotView = (Plot2d_ViewWindow*) vman->getActiveView();
1969 plotView->getViewFrame()->Repaint();
1971 } // ] end of update views
1973 // VISU module opens one SVTK viewer in activateModule(). This causes a bug in save-restore visual
1974 // parameters: it no SVTK view was saved, we need NOT any SVTK on restore. Here we close one
1975 // default SVTK if needed.
1977 QString openedSvtkViewerStr = ip->getProperty( "VtkViewersCount" ).c_str();
1978 int openedSvtkViewer = openedSvtkViewerStr.toInt( &ok );
1979 if ( ok && openedSvtkViewer == 0 ) {
1981 getApp()->viewManagers( SVTK_Viewer::Type(), lst );
1983 lst.at( 0 )->closeAllViews();
1987 // if active Gauss Viewer is set ( != -1) then raise the gauss view window.
1989 QString activeGaussViewerStr = ip->getProperty( "ActiveGaussViewer" ).c_str();
1990 int activeGaussViewer = activeGaussViewerStr.toInt( &ok );
1991 if ( ok && activeGaussViewer != -1 ) {
1993 getApp()->viewManagers( VVTK_Viewer::Type(), lst );
1994 if ( activeGaussViewer >= 0 && activeGaussViewer < lst.count() ) {
1995 SUIT_ViewWindow* activeView = lst.at( activeGaussViewer )->getActiveView();
1997 activeView->setActiveWindow();
1998 activeView->setFocus();