1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "GEOMGUI_AnnotationMgr.h"
22 #include <GEOMGUI_AnnotationAttrs.h>
23 #include <GEOM_Annotation.hxx>
24 #include <GEOM_Client.hxx>
25 #include <GEOM_Constants.h>
26 #include <GEOM_Displayer.h>
27 #include <GEOMGUI_TextTreeWdg.h>
29 #include <GeometryGUI.h>
31 #include <SalomeApp_Application.h>
32 #include <SalomeApp_Study.h>
33 #include <SALOME_Prs.h>
35 #include <SUIT_ResourceMgr.h>
36 #include <SUIT_Session.h>
37 #include <SUIT_Desktop.h>
38 #include <SUIT_ViewWindow.h>
39 #include <SUIT_ViewManager.h>
42 #include <SOCC_ViewWindow.h>
44 #include <Quantity_Color.hxx>
45 #include <TCollection_AsciiString.hxx>
48 #include <TopoDS_Shape.hxx>
49 #include <TopTools_IndexedMapOfShape.hxx>
51 #include <AIS_ListIteratorOfListOfInteractive.hxx>
57 GEOMGUI_AnnotationMgr::GEOMGUI_AnnotationMgr( SalomeApp_Application* theApplication )
58 : myApplication( theApplication )
62 QString GEOMGUI_AnnotationMgr::GetEntrySeparator()
64 return "_annotation:";
67 //================================================================
68 // Function : CreatePresentation
70 //================================================================
71 SALOME_Prs* GEOMGUI_AnnotationMgr::CreatePresentation( const GEOMGUI_AnnotationAttrs::Properties& theProperty,
72 GEOM::GEOM_Object_ptr theObject,
74 const QString& theEntry )
76 SOCC_Viewer* aView = viewOrActiveView( theView );
81 Handle ( GEOM_Annotation ) aPresentation = new GEOM_Annotation();
82 if ( !theEntry.isEmpty() ) {
83 // owner should be set to provide selection mechanizm
84 Handle( SALOME_InteractiveObject ) anIO = new SALOME_InteractiveObject();
85 anIO->setEntry( theEntry.toLatin1().constData() );
86 aPresentation->SetOwner( anIO );
89 aPresentation->SetIsScreenFixed( theProperty.IsScreenFixed );
91 TopoDS_Shape aShape = GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObject );
92 if ( !aShape.IsNull() ) {
94 gp_Ax3 aShapeLCS = gp_Ax3().Transformed( aShape.Location().Transformation() );
96 GEOMGUI_AnnotationAttrs::SetupPresentation( aPresentation, theProperty, aShapeLCS );
98 if ( theProperty.ShapeType == TopAbs_SHAPE ) {
100 aPresentation->SetHilightShape( aShape );
102 else if ( theProperty.ShapeIndex > 0 ) {
104 TopTools_IndexedMapOfShape aSubShapeMap;
105 TopExp::MapShapes( aShape, static_cast<TopAbs_ShapeEnum>( theProperty.ShapeType ), aSubShapeMap );
106 if ( theProperty.ShapeIndex <= aSubShapeMap.Extent() ) {
108 aPresentation->SetHilightShape( aSubShapeMap( theProperty.ShapeIndex ) );
113 setDisplayProperties( aPresentation, aView, getEntry( theObject ).c_str() );
115 // add Prs to preview
116 SUIT_ViewWindow* vw = getApplication()->desktop()->activeWindow();
118 dynamic_cast<SOCC_Prs*>( ( aView )->CreatePrs( 0 ) );
121 aPrs->AddObject( aPresentation );
126 bool GEOMGUI_AnnotationMgr::IsDisplayed( const QString& theEntry, const int theIndex, SOCC_Viewer* theView ) const
128 SOCC_Viewer* aView = viewOrActiveView( theView );
129 if ( !aView || !myVisualized.contains( aView ) )
132 EntryToAnnotations anEntryToAnnotation = myVisualized[aView];
133 if ( !anEntryToAnnotation.contains( theEntry ) )
136 AnnotationToPrs anAnnotationToPrs = anEntryToAnnotation[theEntry];
137 if ( !anAnnotationToPrs.contains( theIndex ) )
143 //=======================================================================
144 // function : GEOMGUI_AnnotationMgr::Display
145 // purpose : Displays annotation shape presentation in view. It creates an annotation presentation
146 // and stores it in an internal container
147 //=======================================================================
148 void GEOMGUI_AnnotationMgr::Display( const QString& theEntry, const int theIndex, SOCC_Viewer* theView,
149 const bool isStoreViewState, const bool isUpdateViewer )
151 SOCC_Viewer* aView = viewOrActiveView( theView );
155 if ( IsDisplayed( theEntry, theIndex, aView ) )
158 GEOMGUI_AnnotationAttrs::Properties aProperty;
159 GEOM::GEOM_Object_ptr anObject;
160 getObject( theEntry, theIndex, anObject, aProperty );
162 // display presentation in the viewer
163 QString anEntry = QString("%1%2%3").arg(theEntry).arg(GetEntrySeparator()).arg(theIndex);
164 SALOME_Prs* aPrs = CreatePresentation( aProperty, anObject, aView, anEntry );
165 ((SALOME_View*)aView)->Display( getDisplayer(), aPrs );
166 if ( isUpdateViewer )
167 getDisplayer()->UpdateViewer();
169 EntryToAnnotations anEntryToMap;
170 if ( myVisualized.contains( aView ) )
171 anEntryToMap = myVisualized[aView];
173 // store displayed parameters to an internal container
174 AnnotationToPrs anAnnotationToPrsMap;
175 if ( anEntryToMap.contains( theEntry ) )
176 anAnnotationToPrsMap = anEntryToMap[theEntry];
177 anAnnotationToPrsMap[theIndex] = aPrs;
178 anEntryToMap[theEntry] = anAnnotationToPrsMap;
179 myVisualized[aView] = anEntryToMap;
181 if ( isStoreViewState ) {
182 // change persistent for the entry: set visible state in true for indices which presentations are shown
183 storeVisibleState( theEntry, theView );
184 storeFixedPosition( theEntry, theView );
188 void GEOMGUI_AnnotationMgr::Redisplay( const QString& theEntry, const int theIndex,
189 const GEOMGUI_AnnotationAttrs::Properties& theProperty )
191 SUIT_Session* ses = SUIT_Session::session();
192 SUIT_Application* app = ses->activeApplication();
195 SUIT_Desktop* desk = app->desktop();
196 QList<SUIT_ViewWindow*> wnds = desk->windows();
197 SUIT_ViewWindow* wnd;
198 QListIterator<SUIT_ViewWindow*> it( wnds );
199 while ( it.hasNext() && (wnd = it.next()) )
201 SUIT_ViewManager* vman = wnd->getViewManager();
204 SUIT_ViewModel* vmodel = vman->getViewModel();
207 SOCC_Viewer* aView = dynamic_cast<SOCC_Viewer*>(vmodel);
209 Redisplay( theEntry, theIndex, theProperty, aView );
216 void GEOMGUI_AnnotationMgr::Redisplay( const QString& theEntry, const int theIndex,
217 const GEOMGUI_AnnotationAttrs::Properties& theProperty,
218 SOCC_Viewer* theView )
220 SOCC_Viewer* aView = viewOrActiveView( theView );
224 if ( !myVisualized.contains( aView ) )
227 EntryToAnnotations anEntryToAnnotation = myVisualized[aView];
228 if ( !anEntryToAnnotation.contains( theEntry ) )
231 AnnotationToPrs anAnnotationToPrs = anEntryToAnnotation[theEntry];
232 if ( !anAnnotationToPrs.contains( theIndex ) )
235 GEOMGUI_AnnotationAttrs::Properties aProperty;
236 GEOM::GEOM_Object_ptr anObject;
237 getObject( theEntry, theIndex, anObject, aProperty );
238 TopoDS_Shape aShape = GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), anObject );
239 gp_Ax3 aShapeLCS = gp_Ax3().Transformed( aShape.Location().Transformation() );
241 // erase presentation from the viewer
242 SALOME_Prs* aPrs = anAnnotationToPrs[theIndex];
243 SOCC_Prs* anOCCPrs = dynamic_cast<SOCC_Prs*>( aPrs );
245 AIS_ListOfInteractive anIOs;
246 anOCCPrs->GetObjects( anIOs );
247 AIS_ListIteratorOfListOfInteractive anIter( anIOs );
249 for ( ; anIter.More(); anIter.Next() ) {
250 Handle(AIS_InteractiveObject) aPrs = anIter.Value();
251 Handle(GEOM_Annotation) aPresentation = Handle(GEOM_Annotation)::DownCast( aPrs );
253 GEOMGUI_AnnotationAttrs::SetupPresentation( aPresentation, theProperty, aShapeLCS );
254 aView->getAISContext()->Redisplay( aPresentation, Standard_True );
259 void GEOMGUI_AnnotationMgr::Erase( const QString& theEntry, const int theIndex, SOCC_Viewer* theView,
260 const bool isUpdateViewer )
262 SOCC_Viewer* aView = viewOrActiveView( theView );
266 if ( !myVisualized.contains( aView ) )
269 EntryToAnnotations anEntryToAnnotation = myVisualized[aView];
270 if ( !anEntryToAnnotation.contains( theEntry ) )
273 AnnotationToPrs anAnnotationToPrs = anEntryToAnnotation[theEntry];
274 if ( !anAnnotationToPrs.contains( theIndex ) )
277 // erase presentation from the viewer
278 SALOME_Prs* aPrs = anAnnotationToPrs[theIndex];
279 ((SALOME_View*)aView)->Erase( getDisplayer(), aPrs );
280 if ( isUpdateViewer )
281 getDisplayer()->UpdateViewer();
283 // remove displayed parameters from an internal container
284 anAnnotationToPrs.remove( theIndex );
285 anEntryToAnnotation[theEntry] = anAnnotationToPrs;
286 if (anAnnotationToPrs.isEmpty()) {
287 anEntryToAnnotation.remove( theEntry );
290 anEntryToAnnotation[theEntry] = anAnnotationToPrs;
292 myVisualized[aView] = anEntryToAnnotation;
294 // change persistent for the entry: set visible state in true for indices which presentations are shown
295 storeVisibleState( theEntry, theView );
298 void GEOMGUI_AnnotationMgr::DisplayVisibleAnnotations( const QString& theEntry, SOCC_Viewer* theView,
299 const bool isUpdateViewer )
301 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( getApplication()->activeStudy() );
302 _PTR(SObject) aSObj = aStudy->studyDS()->FindObjectID( theEntry.toStdString() );
303 const Handle(GEOMGUI_AnnotationAttrs) aShapeAnnotations = GEOMGUI_AnnotationAttrs::FindAttributes( aSObj );
304 if ( !aShapeAnnotations.IsNull() ) {
305 const int aCount = aShapeAnnotations->GetNbAnnotation();
306 std::vector<bool> isVisible( aCount );
307 for ( int anIndex = 0; anIndex < aCount; ++anIndex )
309 isVisible[anIndex] = aShapeAnnotations->GetIsVisible( anIndex );
311 for ( int anIndex = 0; anIndex < aCount; ++anIndex )
313 if ( isVisible[anIndex] )
314 Display( theEntry, anIndex, theView, true, isUpdateViewer );
319 void GEOMGUI_AnnotationMgr::EraseVisibleAnnotations( const QString& theEntry, SOCC_Viewer* theView,
320 const bool isUpdateViewer )
322 SOCC_Viewer* aView = viewOrActiveView( theView );
323 if ( !myVisualized.contains( aView ) )
326 EntryToAnnotations anEntryToAnnotation = myVisualized[aView];
327 if ( !anEntryToAnnotation.contains( theEntry ) )
329 AnnotationToPrs anAnnotationToPrs = anEntryToAnnotation[theEntry];
331 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( getApplication()->activeStudy() );
332 _PTR(SObject) aSObj = aStudy->studyDS()->FindObjectID( theEntry.toStdString() );
333 const Handle(GEOMGUI_AnnotationAttrs) aShapeAnnotations = GEOMGUI_AnnotationAttrs::FindAttributes( aSObj );
335 const int aCount = aShapeAnnotations->GetNbAnnotation();
336 for ( int anIndex = 0; anIndex < aCount; ++anIndex )
338 if ( !anAnnotationToPrs.contains( anIndex ) )
341 // erase presentation from the viewer
342 SALOME_Prs* aPrs = anAnnotationToPrs[anIndex];
343 ((SALOME_View*)aView)->Erase( getDisplayer(), aPrs );
345 if ( isUpdateViewer )
346 getDisplayer()->UpdateViewer();
347 anEntryToAnnotation.remove( theEntry );
348 myVisualized[aView] = anEntryToAnnotation;
351 //=======================================================================
352 // function : GEOMGUI_AnnotationMgr::EraseRemovedAnnotation
353 // purpose : Method to update internal maps after removing an
354 // annotation from the object.
355 //=======================================================================
356 void GEOMGUI_AnnotationMgr::EraseRemovedAnnotation( const QString& theEntry, const int theIndex )
358 QMap<SOCC_Viewer*, EntryToAnnotations>::iterator aEntryMapIt = myVisualized.begin();
359 for ( ; aEntryMapIt != myVisualized.end(); ++aEntryMapIt ) {
360 SOCC_Viewer* aView = aEntryMapIt.key();
361 EntryToAnnotations& anEntryToAnnotation = aEntryMapIt.value();
362 if ( !anEntryToAnnotation.contains( theEntry ) )
365 AnnotationToPrs aUpdatedToPrs;
366 AnnotationToPrs& anAnnotationToPrs = anEntryToAnnotation[theEntry];
367 AnnotationToPrs::iterator anAnnotationIt = anAnnotationToPrs.begin();
368 for ( ; anAnnotationIt != anAnnotationToPrs.end(); ++anAnnotationIt ) {
370 const int aIndex = anAnnotationIt.key();
371 SALOME_Prs* aPrs = anAnnotationIt.value();
372 if ( aIndex > theIndex ) {
373 aUpdatedToPrs[aIndex - 1] = aPrs;
375 else if ( aIndex != theIndex ) {
376 aUpdatedToPrs[aIndex] = aPrs;
379 ((SALOME_View*)aView)->Erase( getDisplayer(), aPrs );
383 anAnnotationToPrs = aUpdatedToPrs;
385 getDisplayer()->UpdateViewer();
388 //=======================================================================
389 // function : GEOMGUI_AnnotationMgr::UpdateVisibleAnnotations
391 //=======================================================================
392 void GEOMGUI_AnnotationMgr::UpdateVisibleAnnotations( const QString& theEntry, SOCC_Viewer* theView )
394 SOCC_Viewer* aView = viewOrActiveView( theView );
395 if ( !myVisualized.contains( aView ) )
398 EntryToAnnotations& anEntryToAnnotation = myVisualized[aView];
399 if ( !anEntryToAnnotation.contains( theEntry ) )
402 AnnotationToPrs& anAnnotationToPrs = anEntryToAnnotation[theEntry];
403 AnnotationToPrs::iterator anIt = anAnnotationToPrs.begin();
404 for (; anIt != anAnnotationToPrs.end(); ++anIt ) {
406 dynamic_cast<SOCC_Prs*> (anIt.value());
408 GEOMGUI_AnnotationAttrs::Properties aProperty;
409 GEOM::GEOM_Object_ptr anObject;
410 getObject( theEntry, anIt.key(), anObject, aProperty );
411 TopoDS_Shape aShape = GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), anObject );
412 gp_Ax3 aShapeLCS = gp_Ax3().Transformed( aShape.Location().Transformation() );
414 AIS_ListOfInteractive aIObjects;
415 aPrs->GetObjects( aIObjects );
416 AIS_ListOfInteractive::Iterator aIOIt( aIObjects );
417 for ( ; aIOIt.More(); aIOIt.Next() ) {
419 Handle(GEOM_Annotation) aPresentation =
420 Handle(GEOM_Annotation)::DownCast( aIOIt.Value() );
422 if ( aPresentation.IsNull() )
425 if ( !aShape.IsNull() ) {
427 gp_Ax3 aShapeLCS = gp_Ax3().Transformed( aShape.Location().Transformation() );
428 GEOMGUI_AnnotationAttrs::SetupPresentation( aPresentation, aProperty, aShapeLCS );
429 if ( aProperty.ShapeType == TopAbs_SHAPE ) {
430 aPresentation->SetHilightShape( aShape );
432 else if ( aProperty.ShapeIndex > 0 ) {
433 TopTools_IndexedMapOfShape aSubShapeMap;
434 TopExp::MapShapes( aShape, static_cast<TopAbs_ShapeEnum>( aProperty.ShapeType ), aSubShapeMap );
435 if ( aProperty.ShapeIndex <= aSubShapeMap.Extent() ) {
436 aPresentation->SetHilightShape( aSubShapeMap( aProperty.ShapeIndex ) );
441 setDisplayProperties( aPresentation, aView, theEntry );
443 aView->getAISContext()->Redisplay( aPresentation, Standard_True );
446 getDisplayer()->UpdateViewer();
449 void GEOMGUI_AnnotationMgr::DisplayAllAnnotations( SOCC_Viewer* theView )
451 SOCC_Viewer* aView = viewOrActiveView( theView );
452 if ( !myVisualized.contains( aView ) )
455 GeometryGUI* aModule = dynamic_cast<GeometryGUI*>( getApplication()->activeModule() );
456 GEOMGUI_TextTreeWdg* aTextWidget = aModule->GetTextTreeWdg();
457 QList<QString> anEntries = aTextWidget->getAllEntries( GEOMGUI_TextTreeWdg::AnnotationShape );
459 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( getApplication()->activeStudy() );
460 for ( int i = 0, aCount = anEntries.size(); i < aCount; i++ ) {
461 QString anEntry = anEntries[i];
463 _PTR(SObject) aSObj = aStudy->studyDS()->FindObjectID( anEntry.toStdString() );
467 const Handle(GEOMGUI_AnnotationAttrs) aShapeAnnotations = GEOMGUI_AnnotationAttrs::FindAttributes( aSObj );
468 if ( aShapeAnnotations.IsNull() )
471 int anAnnotationsCount = aShapeAnnotations->GetNbAnnotation();
472 for ( int anIndex = 0; anIndex < anAnnotationsCount; ++anIndex )
474 Display( anEntry, anIndex, aView, false, false );
476 getDisplayer()->UpdateViewer();
477 storeVisibleState( anEntry, aView );
478 storeFixedPosition( anEntry, aView );
482 void GEOMGUI_AnnotationMgr::EraseAllAnnotations( SOCC_Viewer* theView )
484 SOCC_Viewer* aView = viewOrActiveView( theView );
485 if ( !myVisualized.contains( aView ) )
488 GeometryGUI* aModule = dynamic_cast<GeometryGUI*>( getApplication()->activeModule() );
489 GEOMGUI_TextTreeWdg* aTextWidget = aModule->GetTextTreeWdg();
490 QList<QString> anEntries = aTextWidget->getAllEntries( GEOMGUI_TextTreeWdg::AnnotationShape );
492 for ( int i = 0, aCount = anEntries.size(); i < aCount; i++ ) {
493 QString anEntry = anEntries[i];
494 EraseVisibleAnnotations( anEntry, aView, false );
495 storeVisibleState( anEntry, aView );
497 getDisplayer()->UpdateViewer();
500 void GEOMGUI_AnnotationMgr::SetPreviewStyle( const QString& theEntry, const int theIndex, const bool theIsPreview )
502 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
503 const QColor aFontColor = aResMgr->colorValue( "Geometry", "shape_annotation_font_color", QColor( 255, 255, 255 ) );
504 const QColor aLineColor = aResMgr->colorValue( "Geometry", "shape_annotation_line_color", QColor( 255, 255, 255 ) );
506 const Quantity_Color aOcctFontColor( aFontColor.redF(), aFontColor.greenF(), aFontColor.blueF(), Quantity_TOC_RGB );
507 const Quantity_Color aOcctLineColor( aLineColor.redF(), aLineColor.greenF(), aLineColor.blueF(), Quantity_TOC_RGB );
509 QMap<SOCC_Viewer*, EntryToAnnotations>::Iterator aViewIt = myVisualized.begin();
510 for (; aViewIt != myVisualized.end(); ++aViewIt ) {
512 Handle(GEOM_Annotation) aPresentation = getAISPresentation ( theEntry, theIndex, aViewIt.key() );
513 if ( aPresentation.IsNull() ) {
517 if ( theIsPreview ) {
518 aPresentation->SetTextColor( Quantity_NOC_VIOLET );
519 aPresentation->SetLineColor( Quantity_NOC_VIOLET );
520 aPresentation->SetDepthCulling( Standard_False );
523 aPresentation->SetTextColor( aOcctFontColor );
524 aPresentation->SetLineColor( aOcctLineColor );
525 aPresentation->SetDepthCulling( Standard_True );
528 getDisplayer()->UpdateViewer();
531 Handle(SALOME_InteractiveObject) GEOMGUI_AnnotationMgr::FindInteractiveObject( const QString& theEntry,
533 SOCC_Viewer* theView ) const
535 Handle(SALOME_InteractiveObject) anIO;
537 SOCC_Viewer* aView = viewOrActiveView( theView );
538 if ( !myVisualized.contains( aView ) )
541 EntryToAnnotations anEntryToAnnotation = myVisualized[aView];
542 if ( !anEntryToAnnotation.contains( theEntry ) )
545 AnnotationToPrs anAnnotationToPrs = anEntryToAnnotation[theEntry];
546 if ( !anAnnotationToPrs.contains(theIndex) )
549 SALOME_Prs* aPrs = anAnnotationToPrs[theIndex];
550 SOCC_Prs* anOCCPrs = dynamic_cast<SOCC_Prs*>( aPrs );
554 AIS_ListOfInteractive anIOs;
555 anOCCPrs->GetObjects( anIOs );
556 AIS_ListIteratorOfListOfInteractive anIter( anIOs );
557 for ( ; anIter.More() && anIO.IsNull(); anIter.Next() ) {
558 Handle(AIS_InteractiveObject) aPrs = anIter.Value();
559 if ( aPrs->GetOwner() )
560 anIO = Handle(SALOME_InteractiveObject)::DownCast( aPrs->GetOwner() );
565 int GEOMGUI_AnnotationMgr::FindAnnotationIndex( Handle(SALOME_InteractiveObject) theIO,
566 SOCC_Viewer* theView )
570 SOCC_Viewer* aView = viewOrActiveView( theView );
571 if ( !myVisualized.contains( aView ) )
574 QString anEntry = theIO->getEntry();
576 EntryToAnnotations anEntryToAnnotation = myVisualized[aView];
577 if ( !anEntryToAnnotation.contains( anEntry ) )
580 AnnotationToPrs anAnnotationToPrs = anEntryToAnnotation[anEntry];
581 //typedef QMap<int, SALOME_Prs*> AnnotationToPrs;
582 AnnotationToPrs::const_iterator anIt = anAnnotationToPrs.begin(),
583 aLast = anAnnotationToPrs.end();
584 for (; anIt != aLast && anIndex < 0; anIt++) {
585 SALOME_Prs* aPrs = anIt.value();
586 SOCC_Prs* anOCCPrs = dynamic_cast<SOCC_Prs*>( aPrs );
590 AIS_ListOfInteractive anIOs;
591 anOCCPrs->GetObjects( anIOs );
592 AIS_ListIteratorOfListOfInteractive anIter( anIOs );
593 for ( ; anIter.More() && anIndex < 0; anIter.Next() ) {
594 Handle(AIS_InteractiveObject) aPrs = anIter.Value();
595 if ( aPrs->GetOwner() ) {
596 Handle(SALOME_InteractiveObject) aPrsOwner = Handle(SALOME_InteractiveObject)::DownCast(aPrs->GetOwner());
597 if ( aPrsOwner == theIO )
598 anIndex = anIt.key();
606 //=======================================================================
607 // function : GEOMGUI_AnnotationMgr::RemoveView
609 //=======================================================================
610 void GEOMGUI_AnnotationMgr::RemoveView( SOCC_Viewer* theView )
612 if ( !theView && myVisualized.contains( theView ) )
613 myVisualized.remove( theView );
616 QString GEOMGUI_AnnotationMgr::getDisplayedIndicesInfo( const QString& theEntry, SOCC_Viewer* theView ) const
618 QString aDisplayedIndices;
620 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( getApplication()->activeStudy() );
621 _PTR(SObject) aSObj = aStudy->studyDS()->FindObjectID( theEntry.toStdString() );
624 return aDisplayedIndices;
626 const Handle(GEOMGUI_AnnotationAttrs) aShapeAnnotations = GEOMGUI_AnnotationAttrs::FindAttributes( aSObj );
627 if ( !aShapeAnnotations.IsNull() )
629 const int aCount = aShapeAnnotations->GetNbAnnotation();
630 QStringList anIndices;
631 for ( int anIndex = 0; anIndex < aCount; ++anIndex )
633 if (IsDisplayed( theEntry, anIndex, theView ) )
634 anIndices.append( QString::number(anIndex) );
636 aDisplayedIndices = anIndices.join(";");
638 return aDisplayedIndices;
641 void GEOMGUI_AnnotationMgr::setDisplayedIndicesInfo( const QString& theEntry, SOCC_Viewer* theView,
642 const QString theIndicesInfo )
644 if ( theIndicesInfo.isEmpty() )
647 QStringList anIndices = theIndicesInfo.split( ";" );
648 for ( int i = 0, aCount = anIndices.size(); i < aCount; i++ ) {
649 Display( theEntry, anIndices[i].toInt(), theView );
653 GEOM_Displayer* GEOMGUI_AnnotationMgr::getDisplayer() const
655 LightApp_Module* aModule = dynamic_cast<LightApp_Module*>( getApplication()->activeModule() );
656 return dynamic_cast<GEOM_Displayer*>( aModule->displayer() );
659 SOCC_Viewer* GEOMGUI_AnnotationMgr::viewOrActiveView( SOCC_Viewer* theView ) const
661 SOCC_Viewer* aView = theView;
663 SalomeApp_Application* anApp = getApplication();
664 SUIT_ViewWindow* anActiveWindow = anApp->desktop()->activeWindow();
665 if ( anActiveWindow ) {
666 aView = dynamic_cast<SOCC_Viewer*>( anActiveWindow->getViewManager()->getViewModel() );
672 QString GEOMGUI_AnnotationMgr::makeAnnotationEntry( const QString& theEntry, const int theIndex )
674 return QString("%1%2%3").arg(theEntry).arg(GetEntrySeparator()).arg(theIndex);
677 bool GEOMGUI_AnnotationMgr::getIndexFromEntry( const QString& theEntry, QString& theObjEntry, int& theIndex )
679 QStringList aSplit = theEntry.split( GetEntrySeparator() );
680 if ( aSplit.size() < 2 )
684 theObjEntry = aSplit.at( 0 );
685 theIndex = aSplit.at( 1 ).toInt( &isOk );
689 void GEOMGUI_AnnotationMgr::getObject( const QString& theEntry, const int theIndex,
690 GEOM::GEOM_Object_ptr& theObject,
691 GEOMGUI_AnnotationAttrs::Properties& theProperty )
693 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( getApplication()->activeStudy() );
694 _PTR(SObject) aSObj = aStudy->studyDS()->FindObjectID( theEntry.toStdString() );
695 const Handle(GEOMGUI_AnnotationAttrs) aShapeAnnotations = GEOMGUI_AnnotationAttrs::FindAttributes( aSObj );
696 if ( !aShapeAnnotations.IsNull() ) {
697 aShapeAnnotations->GetProperties( theIndex, theProperty );
699 theObject = GEOM::GEOM_Object::_narrow( GeometryGUI::ClientSObjectToObject(aSObj) );
703 void GEOMGUI_AnnotationMgr::storeFixedPosition( const QString& theEntry, SOCC_Viewer* theView )
705 SOCC_Viewer* aView = viewOrActiveView( theView );
706 if ( !aView || !myVisualized.contains( aView ) )
709 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( getApplication()->activeStudy() );
710 _PTR(SObject) aSObj = aStudy->studyDS()->FindObjectID( theEntry.toStdString() );
711 const Handle(GEOMGUI_AnnotationAttrs) aShapeAnnotations = GEOMGUI_AnnotationAttrs::FindAttributes( aSObj );
712 if ( aShapeAnnotations.IsNull() )
716 EntryToAnnotations anEntryToAnnotation = myVisualized[aView];
717 AnnotationToPrs anAnnotationToPrs;
718 if ( anEntryToAnnotation.contains( theEntry ) )
719 anAnnotationToPrs = anEntryToAnnotation[theEntry];
721 AnnotationToPrs::iterator anIt = anAnnotationToPrs.begin();
722 for (; anIt != anAnnotationToPrs.end(); ++anIt ) {
723 int anIndex = anIt.key();
724 bool isFixedAnnotation = aShapeAnnotations->GetIsScreenFixed( anIndex );
725 if ( !isFixedAnnotation )
728 SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*> (anIt.value());
729 Handle(GEOM_Annotation) anAnnotationPresentation;
731 AIS_ListOfInteractive aIObjects;
732 aPrs->GetObjects( aIObjects );
733 AIS_ListOfInteractive::Iterator aIOIt( aIObjects );
734 for ( ; aIOIt.More(); aIOIt.Next() ) {
735 anAnnotationPresentation = Handle(GEOM_Annotation)::DownCast( aIOIt.Value() );
736 if ( !anAnnotationPresentation.IsNull() )
739 if ( !anAnnotationPresentation.IsNull() )
740 aShapeAnnotations->SetPosition( anIndex, anAnnotationPresentation->GetPosition() );
744 void GEOMGUI_AnnotationMgr::storeVisibleState( const QString& theEntry, SOCC_Viewer* theView )
746 SOCC_Viewer* aView = viewOrActiveView( theView );
747 if ( !aView || !myVisualized.contains( aView ) )
750 EntryToAnnotations anEntryToAnnotation = myVisualized[aView];
751 AnnotationToPrs anAnnotationToPrs;
752 if ( anEntryToAnnotation.contains( theEntry ) )
753 anAnnotationToPrs = anEntryToAnnotation[theEntry];
756 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( getApplication()->activeStudy() );
757 _PTR(SObject) aSObj = aStudy->studyDS()->FindObjectID( theEntry.toStdString() );
758 const Handle(GEOMGUI_AnnotationAttrs) aShapeAnnotations = GEOMGUI_AnnotationAttrs::FindAttributes( aSObj );
759 if ( !aShapeAnnotations.IsNull() ) {
760 const int aCount = aShapeAnnotations->GetNbAnnotation();
761 for ( int anIndex = 0; anIndex < aCount; ++anIndex ) {
762 bool aVisible = anAnnotationToPrs.contains( anIndex );
763 aShapeAnnotations->SetIsVisible( anIndex, aVisible );
768 //=======================================================================
769 // function : GEOMGUI_AnnotationMgr::getEntry
771 //=======================================================================
772 std::string GEOMGUI_AnnotationMgr::getEntry( const GEOM::GEOM_Object_ptr theObject )
774 SUIT_Session* session = SUIT_Session::session();
775 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
778 CORBA::String_var IOR = app->orb()->object_to_string( theObject );
779 if ( strcmp(IOR.in(), "") != 0 )
781 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
782 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
787 return std::string();
790 //=======================================================================
791 // function : GEOMGUI_AnnotationMgr::getName
793 //=======================================================================
794 std::string GEOMGUI_AnnotationMgr::getName( const GEOM::GEOM_Object_ptr theObject )
796 SUIT_Session* session = SUIT_Session::session();
797 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
800 CORBA::String_var IOR = app->orb()->object_to_string( theObject );
801 if ( strcmp(IOR.in(), "") != 0 )
803 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
804 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
806 _PTR(GenericAttribute) anAttr;
808 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
810 _PTR(AttributeName) aNameAttr( anAttr );
811 return aNameAttr->Value();
815 return std::string();
818 //=======================================================================
819 // function : GEOMGUI_AnnotationMgr::setDisplayProperties
821 //=======================================================================
822 void GEOMGUI_AnnotationMgr::setDisplayProperties( const Handle(GEOM_Annotation)& thePrs,
823 SOCC_Viewer* theView,
824 const QString& theEntry )
826 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
827 const QFont aFont = aResMgr->fontValue( "Geometry", "shape_annotation_font", QFont( "Y14.5M-2009", 24 ) );
828 const QColor aFontColor = aResMgr->colorValue( "Geometry", "shape_annotation_font_color", QColor( 0, 0, 127 ) );
829 const QColor aLineColor = aResMgr->colorValue( "Geometry", "shape_annotation_line_color", QColor( 0, 0, 127 ) );
830 const double aLineWidth = aResMgr->doubleValue( "Geometry", "shape_annotation_line_width", 1.0 );
831 const int aLineStyle = aResMgr->integerValue( "Geometry", "shape_annotation_line_style", 0 );
832 const bool isAutoHide = aResMgr->booleanValue( "Geometry", "shape_annotation_autohide", false );
834 const Quantity_Color aOcctFontColor( aFontColor.redF(), aFontColor.greenF(), aFontColor.blueF(), Quantity_TOC_RGB );
835 const Quantity_Color aOcctLineColor( aLineColor.redF(), aLineColor.greenF(), aLineColor.blueF(), Quantity_TOC_RGB );
836 const Standard_Real aFontHeight = aFont.pixelSize() != -1 ? aFont.pixelSize() : aFont.pointSize();
838 thePrs->SetFont( TCollection_AsciiString( aFont.family().toLatin1().data() ) );
839 thePrs->SetTextHeight( aFontHeight );
840 thePrs->SetTextColor( Quantity_Color( aFontColor.redF(), aFontColor.greenF(), aFontColor.blueF(), Quantity_TOC_RGB ) );
841 thePrs->SetLineColor( Quantity_Color( aLineColor.redF(), aLineColor.greenF(), aLineColor.blueF(), Quantity_TOC_RGB ) );
842 thePrs->SetLineWidth( aLineWidth );
843 thePrs->SetLineStyle( static_cast<Aspect_TypeOfLine>( aLineStyle ) );
844 thePrs->SetAutoHide( isAutoHide ? Standard_True : Standard_False );
845 thePrs->SetDepthCulling( Standard_True );
847 SOCC_Viewer* aView = viewOrActiveView( theView );
848 if ( aView && !theEntry.isEmpty() ) {
850 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( getApplication()->activeStudy() );
851 int aMgrId = dynamic_cast< SUIT_ViewModel* >( aView )->getViewManager()->getGlobalId();
852 QVariant aVal = aStudy->getObjectProperty( aMgrId, theEntry, GEOM::propertyName( GEOM::TopLevel ), QVariant() );
853 bool isBringToFront = aVal.isValid() ? aVal.toBool() : false;
854 if( isBringToFront ) {
855 thePrs->SetZLayer( Graphic3d_ZLayerId_Topmost );
858 thePrs->SetDefaultZLayer();
862 thePrs->SetDefaultZLayer();
866 //=======================================================================
867 // function : GEOMGUI_AnnotationMgr::getAISPresentation
869 //=======================================================================
870 Handle(GEOM_Annotation) GEOMGUI_AnnotationMgr::getAISPresentation ( const QString& theEntry,
872 SOCC_Viewer* theView )
874 if ( !myVisualized.contains( theView ) ) {
875 return Handle(GEOM_Annotation)();
878 EntryToAnnotations& aEntryToAnnotation = myVisualized[theView];
879 if ( !aEntryToAnnotation.contains( theEntry ) ) {
880 return Handle(GEOM_Annotation)();
883 AnnotationToPrs& aAnnotationToPrs = aEntryToAnnotation[theEntry];
884 if ( !aAnnotationToPrs.contains( theIndex ) ) {
885 return Handle(GEOM_Annotation)();
888 SALOME_Prs* aPrs = aAnnotationToPrs[theIndex];
890 // set or unset preview style for the presentation
891 AIS_ListOfInteractive aIObjects;
892 ((SOCC_Prs*)aPrs)->GetObjects( aIObjects );
893 AIS_ListOfInteractive::Iterator aIOIt( aIObjects );
894 for ( ; aIOIt.More(); aIOIt.Next() ) {
895 return Handle(GEOM_Annotation)::DownCast( aIOIt.Value() );
898 return Handle(GEOM_Annotation)();