1 #include "SOCC_ViewModel.h"
\r
3 #include "SOCC_Prs.h"
\r
4 #include "SOCC_ViewWindow.h"
\r
6 #include "SUIT_Session.h"
\r
7 #include "SUIT_Application.h"
\r
9 //#include "ToolsGUI.h"
\r
11 // Temporarily commented to avoid awful dependecy on SALOMEDS
\r
12 // TODO: better mechanism of storing display/erse status in a study
\r
13 // should be provided...
\r
14 //#include <SALOMEconfig.h>
\r
15 //#include CORBA_CLIENT_HEADER(SALOMEDS)
\r
17 #include <AIS_ListIteratorOfListOfInteractive.hxx>
\r
18 #include <Visual3d_View.hxx>
\r
20 #include <SALOME_AISShape.hxx>
\r
21 #include <SALOME_AISObject.hxx>
\r
23 // Temporarily commented to avoid awful dependecy on SALOMEDS
\r
24 // TODO: better mechanism of storing display/erse status in a study
\r
25 // should be provided...
\r
26 //#include <Utils_ORB_INIT.hxx>
\r
27 //#include <Utils_SINGLETON.hxx>
\r
28 //#include <SALOME_ModuleCatalog_impl.hxx>
\r
29 //#include <SALOME_NamingService.hxx>
\r
31 //#include "SALOMEDSClient.hxx"
\r
32 //#include "SALOMEDS_StudyManager.hxx"
\r
34 #include <AIS_TypeOfIso.hxx>
\r
36 // in order NOT TO link with SalomeApp, here the code returns SALOMEDS_Study.
\r
37 // SalomeApp_Study::studyDS() does it as well, but -- here it is retrieved from
\r
38 // SALOMEDS::StudyManager - no linkage with SalomeApp.
\r
40 // Temporarily commented to avoid awful dependecy on SALOMEDS
\r
41 // TODO: better mechanism of storing display/erse status in a study
\r
42 // should be provided...
\r
43 //static _PTR(Study) getStudyDS()
\r
45 // SALOMEDSClient_Study* aStudy = NULL;
\r
46 // _PTR(StudyManager) aMgr( new SALOMEDS_StudyManager() );
\r
48 // get id of SUIT_Study, if it's a SalomeApp_Study, it will return
\r
49 // id of its underlying SALOMEDS::Study
\r
50 // SUIT_Application* app = SUIT_Session::session()->activeApplication();
\r
51 // if ( !app ) return _PTR(Study)(aStudy);
\r
52 // SUIT_Study* stud = app->activeStudy();
\r
53 // if ( !stud ) return _PTR(Study)(aStudy);
\r
54 // const int id = stud->id(); // virtual method, must return SALOMEDS_Study id
\r
55 // get SALOMEDS_Study with this id from StudyMgr
\r
56 // return aMgr->GetStudyByID( id );
\r
59 SOCC_Viewer::SOCC_Viewer( bool DisplayTrihedron )
\r
60 : OCCViewer_Viewer( DisplayTrihedron )
\r
64 SOCC_Viewer::~SOCC_Viewer()
\r
68 bool SOCC_Viewer::highlight( const Handle(SALOME_InteractiveObject)& obj,
\r
69 bool hilight, bool upd )
\r
71 bool isInLocal = getAISContext()->HasOpenedContext();
\r
72 //SUIT_Study* ActiveStudy = SUIT_Application::getDesktop()->getActiveStudy();
\r
73 //SALOME_Selection* Sel = SALOME_Selection::Selection( ActiveStudy->getSelection() );
\r
75 AIS_ListOfInteractive List;
\r
76 getAISContext()->DisplayedObjects(List);
\r
78 AIS_ListIteratorOfListOfInteractive ite(List);
\r
79 for ( ; ite.More(); ite.Next() )
\r
81 Handle(SALOME_InteractiveObject) anObj =
\r
82 Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
\r
84 if ( !anObj.IsNull() && anObj->hasEntry() && anObj->isSame( obj ) )
\r
87 OCCViewer_Viewer::highlight( ite.Value(), hilight, false );
\r
88 // highlight subshapes only when local selection is active
\r
91 /*if ( ite.Value()->IsKind( STANDARD_TYPE( SALOME_AISShape ) ) )
\r
93 Handle(SALOME_AISShape) aSh = Handle(SALOME_AISShape)::DownCast( ite.Value() );
\r
94 TColStd_IndexedMapOfInteger MapIndex;
\r
95 Sel->GetIndex( IObject, MapIndex );
\r
96 aSh->highlightSubShapes( MapIndex, highlight );
\r
109 bool SOCC_Viewer::isInViewer( const Handle(SALOME_InteractiveObject)& obj,
\r
110 bool onlyInViewer )
\r
112 AIS_ListOfInteractive List;
\r
113 getAISContext()->DisplayedObjects(List);
\r
115 if( !onlyInViewer ) {
\r
116 AIS_ListOfInteractive List1;
\r
117 getAISContext()->ObjectsInCollector(List1);
\r
118 List.Append(List1);
\r
121 AIS_ListIteratorOfListOfInteractive ite(List);
\r
122 for ( ; ite.More(); ite.Next() )
\r
124 Handle(SALOME_InteractiveObject) anObj =
\r
125 Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
\r
127 if ( !anObj.IsNull() && anObj->hasEntry() && anObj->isSame( obj ) )
\r
133 bool SOCC_Viewer::isVisible( const Handle(SALOME_InteractiveObject)& obj )
\r
135 AIS_ListOfInteractive List;
\r
136 getAISContext()->DisplayedObjects( List );
\r
138 AIS_ListIteratorOfListOfInteractive ite( List );
\r
139 for ( ; ite.More(); ite.Next() )
\r
141 Handle(SALOME_InteractiveObject) anObj =
\r
142 Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
\r
144 if ( !anObj.IsNull() && anObj->hasEntry() && anObj->isSame( obj ) )
\r
145 return getAISContext()->IsDisplayed( ite.Value() );
\r
151 void SOCC_Viewer::setColor( const Handle(SALOME_InteractiveObject)& obj,
\r
152 const QColor& color, bool update )
\r
154 AIS_ListOfInteractive List;
\r
155 getAISContext()->DisplayedObjects(List);
\r
157 AIS_ListIteratorOfListOfInteractive ite(List);
\r
158 for ( ; ite.More(); ite.Next() )
\r
160 Handle(SALOME_InteractiveObject) anObj =
\r
161 Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
\r
163 if ( !anObj.IsNull() && anObj->hasEntry() && anObj->isSame( obj ) )
\r
165 OCCViewer_Viewer::setColor( ite.Value(), color, update );
\r
171 void SOCC_Viewer::switchRepresentation( const Handle(SALOME_InteractiveObject)& obj,
\r
172 int mode, bool update )
\r
174 AIS_ListOfInteractive List;
\r
175 getAISContext()->DisplayedObjects(List);
\r
177 AIS_ListIteratorOfListOfInteractive ite(List);
\r
178 for ( ; ite.More(); ite.Next() )
\r
180 Handle(SALOME_InteractiveObject) anObj =
\r
181 Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
\r
183 if ( !anObj.IsNull() && anObj->hasEntry() && anObj->isSame( obj ) )
\r
185 OCCViewer_Viewer::switchRepresentation( ite.Value(), mode, update );
\r
191 void SOCC_Viewer::setTransparency( const Handle(SALOME_InteractiveObject)& obj,
\r
192 float trans, bool update )
\r
194 AIS_ListOfInteractive List;
\r
195 getAISContext()->DisplayedObjects( List );
\r
197 AIS_ListIteratorOfListOfInteractive ite( List );
\r
198 for ( ; ite.More(); ite.Next() )
\r
200 Handle(SALOME_InteractiveObject) anObj =
\r
201 Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
\r
203 if ( !anObj.IsNull() && anObj->hasEntry() && anObj->isSame( obj ) )
\r
205 OCCViewer_Viewer::setTransparency( ite.Value(), trans, update );
\r
211 void SOCC_Viewer::rename( const Handle(SALOME_InteractiveObject)& obj,
\r
212 const QString& name )
\r
214 AIS_ListOfInteractive List;
\r
215 getAISContext()->DisplayedObjects(List);
\r
217 AIS_ListIteratorOfListOfInteractive ite(List);
\r
220 if (ite.Value()->IsKind(STANDARD_TYPE(SALOME_AISShape)))
\r
222 Handle(SALOME_AISShape) aSh = Handle(SALOME_AISShape)::DownCast(ite.Value());
\r
224 if ( aSh->hasIO() )
\r
226 Handle(SALOME_InteractiveObject) IO = aSh->getIO();
\r
227 if ( IO->isSame( obj ) )
\r
229 aSh->setName( (char*)name.latin1() );
\r
234 else if ( ite.Value()->IsKind( STANDARD_TYPE( SALOME_AISObject ) ) )
\r
236 Handle(SALOME_AISObject) aSh = Handle(SALOME_AISObject)::DownCast( ite.Value() );
\r
238 // Add code here, if someone create a MODULE_AISObject.
\r
244 //=======================================================================
\r
246 // Purpose : Display presentation
\r
247 //=======================================================================
\r
248 void SOCC_Viewer::Display( const SALOME_OCCPrs* prs )
\r
250 // try do downcast object
\r
251 const SOCC_Prs* anOCCPrs = dynamic_cast<const SOCC_Prs*>( prs );
\r
252 if ( !anOCCPrs || anOCCPrs->IsNull() )
\r
255 // get SALOMEDS Study
\r
256 // Temporarily commented to avoid awful dependecy on SALOMEDS
\r
257 // TODO: better mechanism of storing display/erse status in a study
\r
258 // should be provided...
\r
259 // _PTR(Study) study(getStudyDS());
\r
262 Handle (AIS_InteractiveContext) ic = getAISContext();
\r
264 // get all displayed objects
\r
265 AIS_ListOfInteractive List;
\r
266 ic->DisplayedObjects( List );
\r
267 // get objects in the collector
\r
268 AIS_ListOfInteractive ListCollector;
\r
269 ic->ObjectsInCollector( ListCollector );
\r
271 // get objects to be displayed
\r
272 AIS_ListOfInteractive anAISObjects;
\r
273 anOCCPrs->GetObjects( anAISObjects );
\r
275 AIS_ListIteratorOfListOfInteractive aIter( anAISObjects );
\r
276 for ( ; aIter.More(); aIter.Next() )
\r
278 Handle(AIS_InteractiveObject) anAIS = aIter.Value();
\r
279 if ( !anAIS.IsNull() )
\r
281 // try to find presentation in the viewer
\r
282 bool bDisplayed = false;
\r
283 AIS_ListIteratorOfListOfInteractive ite( List );
\r
284 for ( ; ite.More(); ite.Next() )
\r
286 // compare presentations by handles
\r
287 // if the object is already displayed - nothing to do more
\r
288 if ( ite.Value() == anAIS )
\r
290 // Deactivate object if necessary
\r
291 if ( !anOCCPrs->ToActivate() )
\r
292 ic->Deactivate( anAIS );
\r
301 // then try to find presentation in the collector
\r
302 bDisplayed = false;
\r
303 ite.Initialize( ListCollector );
\r
304 for ( ; ite.More(); ite.Next() )
\r
306 // compare presentations by handles
\r
307 // if the object is in collector - display it
\r
308 if ( ite.Value() == anAIS )
\r
310 ic->DisplayFromCollector( anAIS, false );
\r
312 // Deactivate object if necessary
\r
313 if ( !anOCCPrs->ToActivate() )
\r
314 ic->Deactivate( anAIS );
\r
317 // Set visibility flag
\r
318 // Temporarily commented to avoid awful dependecy on SALOMEDS
\r
319 // TODO: better mechanism of storing display/erse status in a study
\r
320 // should be provided...
\r
321 //Handle(SALOME_InteractiveObject) anObj =
\r
322 // Handle(SALOME_InteractiveObject)::DownCast( anAIS->GetOwner() );
\r
323 //if ( !anObj.IsNull() && anObj->hasEntry() )
\r
326 // ToolsGUI::SetVisibility( study, anObj->getEntry(), true, this );
\r
334 // if object is not displayed and not found in the collector - display it
\r
335 if ( anAIS->IsKind( STANDARD_TYPE(AIS_Trihedron) ) )
\r
337 Handle(AIS_Trihedron) aTrh = Handle(AIS_Trihedron)::DownCast( anAIS );
\r
338 double aNewSize = 100, aSize = 100;
\r
339 getTrihedronSize( aNewSize, aSize );
\r
340 aTrh->SetSize( aTrh == getTrihedron() ? aNewSize : 0.5 * aNewSize );
\r
343 ic->Display( anAIS, false );
\r
345 // Set visibility flag
\r
346 // Temporarily commented to avoid awful dependecy on SALOMEDS
\r
347 // TODO: better mechanism of storing display/erse status in a study
\r
348 // should be provided...
\r
349 //Handle(SALOME_InteractiveObject) anObj =
\r
350 // Handle(SALOME_InteractiveObject)::DownCast( anAIS->GetOwner() );
\r
351 //if ( !anObj.IsNull() && anObj->hasEntry() )
\r
354 // ToolsGUI::SetVisibility( study, anObj->getEntry(), true, this );
\r
357 // Deactivate object if necessary
\r
358 if ( !anOCCPrs->ToActivate() )
\r
359 ic->Deactivate( anAIS );
\r
364 //=======================================================================
\r
366 // Purpose : Erase presentation
\r
367 //=======================================================================
\r
368 void SOCC_Viewer::Erase( const SALOME_OCCPrs* prs, const bool forced )
\r
370 // try do downcast object
\r
371 const SOCC_Prs* anOCCPrs = dynamic_cast<const SOCC_Prs*>( prs );
\r
372 if ( !anOCCPrs || anOCCPrs->IsNull() )
\r
375 // get SALOMEDS Study
\r
376 // Temporarily commented to avoid awful dependecy on SALOMEDS
\r
377 // TODO: better mechanism of storing display/erse status in a study
\r
378 // should be provided...
\r
379 // _PTR(Study) study(getStudyDS());
\r
382 Handle(AIS_InteractiveContext) ic = getAISContext();
\r
384 // get objects to be erased
\r
385 AIS_ListOfInteractive anAISObjects;
\r
386 anOCCPrs->GetObjects( anAISObjects );
\r
388 AIS_ListIteratorOfListOfInteractive aIter( anAISObjects );
\r
389 for ( ; aIter.More(); aIter.Next() ) {
\r
390 Handle(AIS_InteractiveObject) anAIS = aIter.Value();
\r
391 if ( !anAIS.IsNull() ) {
\r
392 // erase the object from context : move it to collector
\r
393 ic->Erase( anAIS, false, forced ? false : true );
\r
395 // Set visibility flag if necessary
\r
396 // Temporarily commented to avoid awful dependecy on SALOMEDS
\r
397 // TODO: better mechanism of storing display/erse status in a study
\r
398 // should be provided...
\r
401 // Handle(SALOME_InteractiveObject) anObj =
\r
402 // Handle(SALOME_InteractiveObject)::DownCast( anAIS->GetOwner() );
\r
403 // if ( !anObj.IsNull() && anObj->hasEntry() )
\r
406 // ToolsGUI::SetVisibility( study, anObj->getEntry(), true, this );
\r
413 //=======================================================================
\r
415 // Purpose : Erase all presentations
\r
416 //=======================================================================
\r
417 void SOCC_Viewer::EraseAll( const bool forced )
\r
419 // get SALOMEDS Study
\r
420 // Temporarily commented to avoid awful dependecy on SALOMEDS
\r
421 // TODO: better mechanism of storing display/erse status in a study
\r
422 // should be provided...
\r
423 // _PTR(Study) study(getStudyDS());
\r
426 Handle(AIS_InteractiveContext) ic = getAISContext();
\r
428 // check if trihedron is displayed
\r
429 Standard_Boolean isTrihedronDisplayed = ic->IsDisplayed( getTrihedron() );
\r
431 // get objects to be erased (all currently displayed objects)
\r
432 AIS_ListOfInteractive aList;
\r
433 ic->DisplayedObjects( aList );
\r
434 AIS_ListIteratorOfListOfInteractive anIter( aList );
\r
435 for ( ; anIter.More(); anIter.Next() ) {
\r
436 if ( isTrihedronDisplayed && anIter.Value()->DynamicType() == STANDARD_TYPE( AIS_Trihedron ) )
\r
440 Handle(AIS_InteractiveObject) anIO = anIter.Value();
\r
441 ic->Erase( anIO, false, forced ? false : true );
\r
443 // Set visibility flag if necessary
\r
444 // Temporarily commented to avoid awful dependecy on SALOMEDS
\r
445 // TODO: better mechanism of storing display/erse status in a study
\r
446 // should be provided...
\r
448 // Handle(SALOME_InteractiveObject) anObj =
\r
449 // Handle(SALOME_InteractiveObject)::DownCast( anIO->GetOwner() );
\r
451 // if ( !anObj.IsNull() && anObj->hasEntry() ) {
\r
453 // ToolsGUI::SetVisibility( study, anObj->getEntry(), true, this );
\r
458 // display trihedron if necessary
\r
459 if ( isTrihedronDisplayed )
\r
460 getAISContext()->Display( getTrihedron() );
\r
465 //=======================================================================
\r
466 // name : CreatePrs
\r
467 // Purpose : Create presentation corresponding to the entry
\r
468 //=======================================================================
\r
469 SALOME_Prs* SOCC_Viewer::CreatePrs( const char* entry )
\r
471 SOCC_Prs* prs = new SOCC_Prs();
\r
475 Handle(AIS_InteractiveContext) ic = getAISContext();
\r
477 // get displayed objects
\r
478 AIS_ListOfInteractive List;
\r
479 ic->DisplayedObjects( List );
\r
480 // get objects in the collector
\r
481 AIS_ListOfInteractive ListCollector;
\r
482 ic->ObjectsInCollector( ListCollector );
\r
483 List.Append( ListCollector );
\r
485 AIS_ListIteratorOfListOfInteractive ite( List );
\r
486 for ( ; ite.More(); ite.Next() )
\r
488 Handle(SALOME_InteractiveObject) anObj =
\r
489 Handle(SALOME_InteractiveObject)::DownCast( ite.Value()->GetOwner() );
\r
491 if ( !anObj.IsNull() && anObj->hasEntry() && strcmp( anObj->getEntry(), entry ) == 0 )
\r
492 prs->AddObject( ite.Value() );
\r
498 //=======================================================================
\r
499 // name : LocalSelection
\r
500 // Purpose : Activates selection of sub shapes
\r
501 //=======================================================================
\r
502 void SOCC_Viewer::LocalSelection( const SALOME_OCCPrs* thePrs, const int theMode )
\r
504 Handle(AIS_InteractiveContext) ic = getAISContext();
\r
506 const SOCC_Prs* anOCCPrs = dynamic_cast<const SOCC_Prs*>( thePrs );
\r
510 // Open local context if there is no one
\r
511 bool allObjects = thePrs == 0 || thePrs->IsNull();
\r
512 if ( !ic->HasOpenedContext() ) {
\r
513 ic->ClearCurrents( false );
\r
514 ic->OpenLocalContext( allObjects, true, true );
\r
517 AIS_ListOfInteractive anObjs;
\r
518 // Get objects to be activated
\r
520 ic->DisplayedObjects( anObjs );
\r
522 anOCCPrs->GetObjects( anObjs );
\r
524 // Activate selection of objects from prs
\r
525 AIS_ListIteratorOfListOfInteractive aIter( anObjs );
\r
526 for ( ; aIter.More(); aIter.Next() ) {
\r
527 Handle(AIS_InteractiveObject) anAIS = aIter.Value();
\r
528 if ( !anAIS.IsNull() )
\r
530 if ( anAIS->IsKind( STANDARD_TYPE( AIS_Shape ) ) )
\r
532 ic->Load( anAIS, -1, false );
\r
533 ic->Activate( anAIS, AIS_Shape::SelectionMode( (TopAbs_ShapeEnum)theMode ) );
\r
535 else if ( anAIS->DynamicType() != STANDARD_TYPE(AIS_Trihedron) )
\r
537 ic->Load( anAIS, -1, false );
\r
538 ic->Activate( anAIS, theMode );
\r
544 //=======================================================================
\r
545 // name : GlobalSelection
\r
546 // Purpose : Deactivates selection of sub shapes
\r
547 //=======================================================================
\r
548 void SOCC_Viewer::GlobalSelection( const bool update ) const
\r
550 Handle(AIS_InteractiveContext) ic = getAISContext();
\r
551 if ( !ic.IsNull() )
\r
553 ic->CloseAllContexts( false );
\r
555 ic->CurrentViewer()->Redraw();
\r
559 //=======================================================================
\r
560 // name : BeforeDisplay
\r
561 // Purpose : Axiluary method called before displaying of objects
\r
562 //=======================================================================
\r
563 void SOCC_Viewer::BeforeDisplay( SALOME_Displayer* d )
\r
565 d->BeforeDisplay( this, SALOME_OCCViewType() );
\r
568 //=======================================================================
\r
569 // name : AfterDisplay
\r
570 // Purpose : Axiluary method called after displaying of objects
\r
571 //=======================================================================
\r
572 void SOCC_Viewer::AfterDisplay( SALOME_Displayer* d )
\r
574 d->AfterDisplay( this, SALOME_OCCViewType() );
\r
577 //=======================================================================
\r
578 // name : getTrihedronSize
\r
579 // Purpose : Get new and current trihedron size corresponding to the
\r
580 // current model size
\r
581 //=======================================================================
\r
582 bool SOCC_Viewer::getTrihedronSize( double& theNewSize, double& theSize )
\r
587 //SRN: BUG IPAL8996, a usage of method ActiveView without an initialization
\r
588 Handle(V3d_Viewer) viewer = getViewer3d();
\r
589 viewer->InitActiveViews();
\r
590 if(!viewer->MoreActiveViews()) return false;
\r
592 Handle(V3d_View) view3d = viewer->ActiveView();
\r
595 if ( view3d.IsNull() )
\r
598 double Xmin = 0, Ymin = 0, Zmin = 0, Xmax = 0, Ymax = 0, Zmax = 0;
\r
601 view3d->View()->MinMaxValues( Xmin, Ymin, Zmin, Xmax, Ymax, Zmax );
\r
603 if ( Xmin == RealFirst() || Ymin == RealFirst() || Zmin == RealFirst() ||
\r
604 Xmax == RealLast() || Ymax == RealLast() || Zmax == RealLast() )
\r
607 aMaxSide = Xmax - Xmin;
\r
608 if ( aMaxSide < Ymax -Ymin ) aMaxSide = Ymax -Ymin;
\r
609 if ( aMaxSide < Zmax -Zmin ) aMaxSide = Zmax -Zmin;
\r
611 float aSizeInPercents = SUIT_Session::session()->resourceMgr()->doubleValue("Viewer","TrihedronSize", 105.);
\r
613 static float EPS = 5.0E-3;
\r
614 theSize = getTrihedron()->Size();
\r
615 theNewSize = aMaxSide*aSizeInPercents / 100.0;
\r
617 return fabs( theNewSize - theSize ) > theSize * EPS ||
\r
618 fabs( theNewSize - theSize) > theNewSize * EPS;
\r
621 //=======================================================================
\r
624 //=======================================================================
\r
625 void SOCC_Viewer::Repaint()
\r
627 // onAdjustTrihedron();
\r
628 getViewer3d()->Update();
\r
631 //=======================================================================
\r
632 // name : createView
\r
633 // Purpose : create SOCC_ViewWindow
\r
634 //=======================================================================
\r
635 SUIT_ViewWindow* SOCC_Viewer::createView( SUIT_Desktop* theDesktop )
\r
637 SOCC_ViewWindow* view = new SOCC_ViewWindow(theDesktop, this);
\r