1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : GEOM_Displayer.cxx
25 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
27 #include "GEOM_Displayer.h"
28 #include "GeometryGUI.h"
30 #include <GEOM_Constants.h>
31 #include <GEOM_TypeFilter.h>
32 #include <GEOM_EdgeFilter.h>
33 #include <GEOM_FaceFilter.h>
34 #include <GEOM_CompoundFilter.h>
35 #include <GEOM_PreviewFilter.h>
36 #include <GEOM_LogicalFilter.h>
37 #include <GEOM_OCCFilter.h>
39 #include <GEOM_Actor.h>
40 #include <GEOM_AISDimension.hxx>
41 #include <GEOM_Annotation.hxx>
42 #include <GEOM_TopWireframeShape.hxx>
43 #include <GEOM_AISVector.hxx>
44 #include <GEOM_AISTrihedron.hxx>
45 #include <GEOM_VTKTrihedron.hxx>
46 #include <GEOM_VTKPropertyMaterial.hxx>
48 #include <GEOMGUI_DimensionProperty.h>
49 #include <GEOMGUI_AnnotationAttrs.h>
50 #include <GEOMGUI_AnnotationMgr.h>
52 #include <GEOMUtils.hxx>
54 #include <Material_Model.h>
56 #include <SUIT_Desktop.h>
57 #include <SUIT_ViewWindow.h>
58 #include <SUIT_Session.h>
59 #include <SUIT_ViewManager.h>
60 #include <SUIT_ResourceMgr.h>
62 #include <SalomeApp_Study.h>
63 #include <SalomeApp_Application.h>
64 #include <LightApp_SelectionMgr.h>
65 #include <LightApp_DataObject.h>
66 #include <SalomeApp_TypeFilter.h>
67 #include <SalomeApp_Tools.h>
68 #include "utilities.h"
70 #include <SALOME_ListIO.hxx>
71 #include <SALOME_Prs.h>
72 #include "utilities.h"
75 #include <SOCC_ViewModel.h>
78 #include <SVTK_ViewModel.h>
80 #include <OCCViewer_ViewWindow.h>
81 #include <OCCViewer_ViewPort3d.h>
82 #include <OCCViewer_Utilities.h>
85 #include <AIS_Dimension.hxx>
86 #include <AIS_LengthDimension.hxx>
87 #include <AIS_DiameterDimension.hxx>
88 #include <AIS_AngleDimension.hxx>
89 #include <AIS_ListIteratorOfListOfInteractive.hxx>
90 #include <Aspect_PolygonOffsetMode.hxx>
91 #include <Prs3d_IsoAspect.hxx>
92 #include <Prs3d_PointAspect.hxx>
93 #include <StdSelect_TypeOfEdge.hxx>
94 #include <StdSelect_TypeOfFace.hxx>
95 #include <StdSelect_DisplayMode.hxx>
96 #include <TopoDS_Face.hxx>
97 #include <BRep_Tool.hxx>
98 #include <Geom_Plane.hxx>
99 #include <Geom_Axis2Placement.hxx>
100 #include <Graphic3d_AspectFillArea3d.hxx>
101 #include <gp_Pln.hxx>
102 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
103 #include <TopoDS_Iterator.hxx>
104 #include <Graphic3d_AspectMarker3d.hxx>
105 #include <TopTools_MapOfShape.hxx>
106 #include <TopTools_ListOfShape.hxx>
107 #include <TopTools_ListIteratorOfListOfShape.hxx>
108 #include <TopoDS.hxx>
109 #include <NCollection_DataMap.hxx>
110 #include <NCollection_Map.hxx>
111 #include <Graphic3d_Texture2Dmanual.hxx>
113 #include <Prs3d_ShadingAspect.hxx>
115 #include <BRepMesh_IncrementalMesh.hxx>
118 #include <vtkActorCollection.h>
119 #include <vtkProperty.h>
122 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
124 #include <GEOMImpl_Types.hxx>
126 #include <TColStd_HArray1OfByte.hxx>
128 // If the next macro is defined, autocolor feature works for all sub-shapes;
129 // if it is undefined, autocolor feature works for groups only
130 #define GENERAL_AUTOCOLOR
131 // Below macro, when uncommented, switches on simplified (more performant) algorithm
132 // of auto-color picking up
133 #define SIMPLE_AUTOCOLOR
135 // Hard-coded value of shape deflection coefficient for VTK viewer
136 const double VTK_MIN_DEFLECTION = 0.001;
137 // If the next macro is defined, the deflection coefficient for VTK presentation
138 // is limited by VTK_MIN_DEFLECTION
139 //#define LIMIT_DEFLECTION_FOR_VTK
141 // Pixmap caching support
144 typedef NCollection_Map<Handle(GEOM_AISShape)> SetOfAISShapes;
145 typedef NCollection_DataMap<Handle(Image_PixMap), SetOfAISShapes> PixmapUsageMap;
146 typedef QMap<QString, Handle(Image_PixMap)> PixmapCacheMap;
148 static inline PixmapUsageMap& getPixmapUsageMap()
150 static PixmapUsageMap aMap;
154 static inline PixmapCacheMap& getPixmapCacheMap()
156 static PixmapCacheMap aMap;
160 //===========================================================================
161 // Function : getDefaultTexture
162 // Purpose : Get default texture
163 //===========================================================================
164 static inline Handle(Image_PixMap) getDefaultTexture()
166 static Handle(Image_PixMap) aPixmap;
167 if ( aPixmap.IsNull() ) {
168 QPixmap px(":images/default_texture.png");
170 aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage() );
175 //===========================================================================
176 // Function : cacheTextureFor
177 // Purpose : Load and cache image for the specified presentation.
178 //===========================================================================
179 static inline Handle(Image_PixMap) cacheTextureFor( const QString& thePath,
180 const Handle(GEOM_AISShape)& theShape )
182 if ( thePath.isEmpty() )
185 PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
186 PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
188 Handle(Image_PixMap) aPixmap = aPixmapCacheMap.value( thePath, NULL );
189 if ( !aPixmap.IsNull() ) {
190 // point that the texture is used by the presentation
191 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
192 aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
194 aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
199 // convert texture to compatible image format
200 QImage anImage = QImage( thePath ).convertToFormat( QImage::Format_ARGB32 );
201 if ( anImage.isNull() )
204 aPixmap = OCCViewer_Utilities::imageToPixmap( anImage );
206 aPixmapCacheMap.insert( thePath, aPixmap );
208 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
209 aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
211 aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
216 //===========================================================================
217 // Function : releaseTextures
218 // Purpose : Releases cached textures found for the specified presentation.
219 //===========================================================================
220 static inline void releaseTextures( const SALOME_OCCPrs* thePrs )
222 const SOCC_Prs* anOccPrs = dynamic_cast<const SOCC_Prs*>( thePrs );
224 AIS_ListOfInteractive aListOfIO;
226 anOccPrs->GetObjects( aListOfIO );
228 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
230 PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
231 PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
233 for ( ; aIterateIO.More(); aIterateIO.Next() )
235 Handle(GEOM_AISShape) aAISShape =
236 Handle(GEOM_AISShape)::DownCast( aIterateIO.Value() );
238 if ( aAISShape.IsNull() )
241 const Handle(Graphic3d_TextureMap)& aTexture = aAISShape->Attributes()->ShadingAspect()->Aspect()->TextureMap();
242 if ( aTexture.IsNull() )
245 const Handle(Image_PixMap)& aPixmap = aTexture->GetImage();
246 if ( aPixmap.IsNull() )
249 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
252 SetOfAISShapes& aUsersShapes = aPixmapUsersMap.ChangeFind( aPixmap );
254 aUsersShapes.Remove( aAISShape );
256 if ( aUsersShapes.IsEmpty() ) {
257 aPixmapUsersMap.UnBind( aPixmap );
258 aPixmapCacheMap.remove( aPixmapCacheMap.key( aPixmap ) );
263 uint randomize( uint size )
265 static bool initialized = false;
266 if ( !initialized ) {
267 qsrand( QDateTime::currentDateTime().toTime_t() );
271 v = uint( (double)( v ) / RAND_MAX * size );
272 v = qMax( uint(0), qMin ( v, size-1 ) );
277 //================================================================
278 // Function : getActiveStudy
279 // Purpose : Get active study, returns 0 if no open study frame
280 //================================================================
281 static inline SalomeApp_Study* getActiveStudy()
283 SUIT_Session* session = SUIT_Session::session();
284 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
286 return ( SalomeApp_Study* )app->activeStudy();
290 static inline int getViewManagerId( SALOME_View* theViewFrame) {
291 SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
292 SUIT_ViewManager* aViewMgr = 0;
294 aViewMgr = aModel->getViewManager();
295 return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
298 //================================================================
299 // Function : getTopAbsMode
300 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
301 // one from GEOMImpl_Types.h
302 //================================================================
303 static inline int getTopAbsMode( const int implType )
307 case GEOM_COMPOUND : return TopAbs_COMPOUND;
308 case GEOM_SOLID : return TopAbs_SOLID;
309 case GEOM_SHELL : return TopAbs_SHELL;
310 case GEOM_FACE : return TopAbs_FACE;
311 case GEOM_WIRE : return TopAbs_WIRE;
312 case GEOM_EDGE : return TopAbs_EDGE;
313 case GEOM_POINT : return TopAbs_VERTEX;
318 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
320 if ( shape.IsNull() )
323 int ret = shape.ShapeType();
325 if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
326 TopoDS_Iterator it(shape, Standard_True, Standard_False);
327 for (; it.More(); it.Next()) {
328 TopoDS_Shape sub_shape = it.Value();
329 if ( sub_shape.IsNull() ) continue;
330 int stype = getMinMaxShapeType( sub_shape, ismin );
331 if ( stype == TopAbs_SHAPE ) continue;
332 if ( ismin && stype > ret )
334 else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
342 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
344 return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
347 //================================================================
348 // Function : getFilter
349 // Purpose : Get filter corresponding to the type of object
350 // from GEOMImpl_Types.h
351 //================================================================
352 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
354 SUIT_SelectionFilter* aFilter;
356 int aTopAbsMode = getTopAbsMode( theMode );
357 if ( aTopAbsMode != -1 )
358 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
362 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
363 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
365 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
366 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
367 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
368 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
369 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
370 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
372 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
374 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
375 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
377 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
383 //================================================================
384 // Function : getComplexFilter
385 // Purpose : Get compound filter corresponding to the type of
386 // object from GEOMImpl_Types.h
387 //================================================================
388 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
390 GEOM_CompoundFilter* aFilter;
392 if(aSubShapes != NULL ) {
393 aFilter = new GEOM_CompoundFilter(getStudy());
394 QList<int> aTopAbsTypes;
395 QList<int>::const_iterator it;
396 for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
397 int topAbsMode = getTopAbsMode(*it);
398 if(topAbsMode != -1 )
399 aTopAbsTypes.append(topAbsMode);
401 aFilter->addSubTypes(aTopAbsTypes);
407 //================================================================
408 // Function : getEntry
410 //================================================================
411 static std::string getEntry( GEOM::GEOM_BaseObject_ptr object )
413 SUIT_Session* session = SUIT_Session::session();
414 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
417 CORBA::String_var IOR = app->orb()->object_to_string( object );
418 if ( strcmp(IOR.in(), "") != 0 )
420 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
421 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
429 //================================================================
430 // Function : getName
432 //================================================================
433 static std::string getName( GEOM::GEOM_BaseObject_ptr object )
435 SUIT_Session* session = SUIT_Session::session();
436 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
439 CORBA::String_var IOR = app->orb()->object_to_string( object );
440 if ( strcmp(IOR.in(), "") != 0 )
442 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
443 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
445 _PTR(GenericAttribute) anAttr;
447 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
449 _PTR(AttributeName) aNameAttr( anAttr );
450 return aNameAttr->Value();
458 //=================================================================
460 * GEOM_Displayer::GEOM_Displayer
463 //=================================================================
464 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
465 : myUpdateColorScale( true ), myIsRedisplayed( false )
468 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
473 SUIT_Session* session = SUIT_Session::session();
474 SUIT_ResourceMgr* resMgr = session->resourceMgr();
476 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
477 myShadingColor = SalomeApp_Tools::color( col );
479 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
480 myHasDisplayMode = false;
482 int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
484 myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
485 myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
486 myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
488 // Next properties provide a way to customize displaying of presentations;
489 // for instance, this is useful for preview
499 // This parameter is used for activisation/deactivisation (selection) of objects to be displayed
502 // Activate parallel vizualisation by default.
503 // It can be switched OFF via the environment variable:
504 // export PARALLEL_VISU=0
505 Standard_Boolean parallel_visu = Standard_True;
506 char* parallel_visu_env = getenv("PARALLEL_VISU");
507 if (parallel_visu_env && atoi(parallel_visu_env) == 0)
508 parallel_visu = Standard_False;
509 BRepMesh_IncrementalMesh::SetParallelDefault(parallel_visu);
513 myFieldDataType = GEOM::FDT_Double;
514 myFieldDimension = 0;
515 myFieldStepRangeMin = 0;
516 myFieldStepRangeMax = 0;
519 //=================================================================
521 * GEOM_Displayer::~GEOM_Displayer
524 //=================================================================
525 GEOM_Displayer::~GEOM_Displayer()
529 //=================================================================
531 * GEOM_Displayer::Display
532 * Display interactive object in the current viewer
534 //=================================================================
535 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
536 const bool updateViewer,
537 SALOME_View* theViewFrame )
539 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
542 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
546 vf->BeforeDisplay( this, prs );
547 vf->Display( this, prs );
548 vf->AfterDisplay( this, prs );
553 delete prs; // delete presentation because displayer is its owner
558 //=================================================================
560 * GEOM_Displayer::Display
561 * This overloaded Display() method can be useful for operations
562 * not using dialog boxes.
564 //=================================================================
565 void GEOM_Displayer::Display( GEOM::GEOM_BaseObject_ptr theObj, const bool updateViewer )
567 if ( theObj->_is_nil() )
570 std::string entry = getEntry( theObj );
572 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
577 //=================================================================
579 * GEOM_Displayer::Erase
580 * Erase interactive object in the current viewer
582 //=================================================================
583 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
585 const bool updateViewer,
586 SALOME_View* theViewFrame )
588 if ( theIO.IsNull() )
591 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
594 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
596 vf->BeforeErase( this, prs );
597 vf->Erase( this, prs, forced );
598 vf->AfterErase( this, prs );
601 delete prs; // delete presentation because displayer is its owner
606 //=================================================================
608 * GEOM_Displayer::Erase
609 * Erase geometry object in the current viewer
611 //=================================================================
612 void GEOM_Displayer::Erase( GEOM::GEOM_BaseObject_ptr theObj,
614 const bool updateViewer,
615 SALOME_View* theViewFrame)
617 std::string entry = getEntry( theObj );
620 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
621 forced, updateViewer, theViewFrame);
625 //=================================================================
627 * GEOM_Displayer::Redisplay
628 * Redisplay (erase and then display again) interactive object
629 * in the current viewer
631 //=================================================================
632 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
633 const bool updateViewer,
634 const bool checkActiveViewer )
636 bool aRedisplayed = myIsRedisplayed;
637 myIsRedisplayed = true;
638 // Remove the object permanently (<forced> == true)
639 SUIT_Session* ses = SUIT_Session::session();
640 SUIT_Application* app = ses->activeApplication();
643 SUIT_Desktop* desk = app->desktop();
644 QList<SUIT_ViewWindow*> wnds = desk->windows();
645 SUIT_ViewWindow* wnd;
646 QListIterator<SUIT_ViewWindow*> it( wnds );
647 while ( it.hasNext() && (wnd = it.next()) )
649 SUIT_ViewManager* vman = wnd->getViewManager();
652 SUIT_ViewModel* vmodel = vman->getViewModel();
655 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
658 if ( view->isVisible( theIO ) || ( checkActiveViewer && view == GetActiveView() ) )
660 Redisplay( theIO, updateViewer, view );
667 myIsRedisplayed = aRedisplayed;
670 //=================================================================
672 * GEOM_Displayer::Redisplay
673 * Redisplay (erase and then display again) interactive object
674 * in the specified view
676 //=================================================================
677 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
678 const bool theUpdateViewer,
679 SALOME_View* theViewFrame )
681 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
687 bool aRedisplayed = myIsRedisplayed;
688 myIsRedisplayed = true;
689 Erase( theIO, true, false, theViewFrame );
690 Display( theIO, theUpdateViewer, theViewFrame );
691 myIsRedisplayed = aRedisplayed;
692 // hide annotations for erased presentation
693 SUIT_Session* session = SUIT_Session::session();
694 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
695 GeometryGUI* aModule = dynamic_cast<GeometryGUI*>( anApp->activeModule() );
697 if ( !theViewFrame->isVisible( theIO ) ) {
698 aModule->GetAnnotationMgr()->EraseVisibleAnnotations(QString(theIO->getEntry()), dynamic_cast<SOCC_Viewer*>( theViewFrame ));
701 aModule->GetAnnotationMgr()->DisplayVisibleAnnotations(QString(theIO->getEntry()), dynamic_cast<SOCC_Viewer*>( theViewFrame ));
706 //=================================================================
708 * GEOM_Displayer::Display
709 * Calls Display() method for each object in the given list
711 //=================================================================
712 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
714 SALOME_ListIteratorOfListIO Iter( theIOList );
715 for ( ; Iter.More(); Iter.Next() ) {
716 Display( Iter.Value(), false );
722 void GEOM_Displayer::UpdateVisibility( SALOME_View* v, const SALOME_Prs* p, bool on )
724 SalomeApp_Study* aStudy = getStudy();
726 if ( v ) vId = getViewManagerId( v );
729 QString entry = p->GetEntry();
730 if ( !entry.isEmpty() ) {
732 aStudy->setObjectProperty( vId, entry, GEOM::propertyName( GEOM::Visibility ), on );
733 setVisibilityState( entry, on ? Qtx::ShownState : Qtx::HiddenState );
738 aStudy->setObjectProperty( vId, GEOM::propertyName( GEOM::Visibility ), on );
743 Quantity_Color GEOM_Displayer::qColorFromResources( const QString& property, const QColor& defColor )
745 // VSR: this method can be improved in future:
746 // to improve performance, the default values from resource manager should be cached in the displayer
747 return SalomeApp_Tools::color( SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor ) );
750 QColor GEOM_Displayer::colorFromResources( const QString& property, const QColor& defColor )
752 // VSR: this method can be improved in future:
753 // to improve performance, the default values from resource manager should be cached in the displayer
754 return SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor );
757 void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShape, bool create )
759 // check that shape is not null
760 if ( AISShape.IsNull() ) return;
762 // check that study is active
763 SalomeApp_Study* study = getStudy();
764 if ( !study ) return;
766 if ( myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
767 !TopoDS_Iterator(myShape).More() )
768 return; // NPAL15983 (Bug when displaying empty groups)
770 // set interactive object
772 Handle( SALOME_InteractiveObject ) anIO;
774 if ( !myIO.IsNull() ) {
775 AISShape->setIO( myIO );
776 AISShape->SetOwner( myIO );
779 else if ( !myName.empty() ) {
780 // workaround to allow selection of temporary objects
781 static int tempId = 0;
782 anIO = new SALOME_InteractiveObject( QString( "TEMP_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
783 AISShape->setIO( anIO );
784 AISShape->SetOwner( anIO );
787 // flag: only vertex or compound of vertices is processed (specific handling)
788 bool onlyVertex = myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape );
789 // presentation study entry (empty for temporary objects like preview)
790 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
791 // flag: temporary object
792 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
793 // currently active view window's ID (-1 if no active view)
794 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
796 // get presentation properties
797 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
799 // Temporary staff: vertex must be infinite for correct visualization
800 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
803 Material_Model material;
804 // if predefined color isn't set in displayer(via GEOM_Displayer::SetColor() function)
806 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
807 // - set front material properties
808 AISShape->SetCurrentFacingModel( Aspect_TOFM_FRONT_SIDE );
809 AISShape->SetMaterial( material.getMaterialOCCAspect( true ) );
810 // - set back material properties
811 AISShape->SetCurrentFacingModel( Aspect_TOFM_BACK_SIDE );
812 AISShape->SetMaterial( material.getMaterialOCCAspect( false ) );
813 // - switch to default (both sides) facing mode
814 AISShape->SetCurrentFacingModel( Aspect_TOFM_BOTH_SIDE );
820 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function;
821 // we set it to the shape not taking into account material properties
822 AISShape->SetShadingColor( (Quantity_NameOfColor)GetColor() );
824 else if ( !material.isPhysical() ) {
825 // shading color from properties is used only for non-physical materials
826 AISShape->SetShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>() ) );
830 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
831 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
832 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
833 AISShape->Attributes()->SetLineAspect( anAspect );
835 // - unfree boundaries color
836 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
837 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
838 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
839 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
841 // - free boundaries color
842 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
843 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
844 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>() ) );
845 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
847 // - standalone edges color
848 anAspect = AISShape->Attributes()->WireAspect();
849 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
850 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>() ) );
851 AISShape->Attributes()->SetWireAspect( anAspect );
853 // - color for edges in shading+edges mode
854 AISShape->SetEdgesInShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
856 // - color of labels (textual fields and shape name)
857 AISShape->SetLabelColor( qColorFromResources( "label_color", QColor( 255, 255, 255 ) ) );
860 int displayMode = HasDisplayMode() ?
861 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
863 // display mode from properties
864 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
865 AISShape->SetDisplayMode( displayMode );
867 // - face boundaries color and line width
868 anAspect = AISShape->Attributes()->FaceBoundaryAspect();
869 anAspect->SetColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
870 anAspect->SetWidth( HasWidth() ? GetWidth() : propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
871 AISShape->Attributes()->SetFaceBoundaryAspect( anAspect );
873 // set display vectors flag
874 AISShape->SetDisplayVectors( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
876 // set display vertices flag
877 bool isVerticesMode = propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool();
878 AISShape->SetDisplayVertices( isVerticesMode );
880 // set display name flag
881 bool isNameMode = propMap.value( GEOM::propertyName( GEOM::ShowName ) ).toBool();
882 AISShape->SetDisplayName( isNameMode );
885 if( HasTransparency() ) {
886 AISShape->SetTransparency( GetTransparency() );
888 AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
891 // set iso properties
892 int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt();
893 int vIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[1].toInt();
894 Quantity_Color isosColor = SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>() );
895 int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt();
896 Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect();
897 Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect();
899 if ( HasIsosColor() ) {
900 uIsoAspect->SetColor( (Quantity_NameOfColor)GetIsosColor() );
901 vIsoAspect->SetColor( (Quantity_NameOfColor)GetIsosColor() );
904 uIsoAspect->SetColor( isosColor );
905 vIsoAspect->SetColor( isosColor );
908 if ( HasIsosWidth() ) {
909 uIsoAspect->SetWidth( GetIsosWidth() );
910 vIsoAspect->SetWidth( GetIsosWidth() );
913 uIsoAspect->SetWidth( isosWidth );
914 vIsoAspect->SetWidth( isosWidth );
918 uIsoAspect->SetNumber( GetNbIsos() );
919 vIsoAspect->SetNumber( GetNbIsos() );
922 uIsoAspect->SetNumber( uIsos );
923 vIsoAspect->SetNumber( vIsos );
926 AISShape->Attributes()->SetUIsoAspect( uIsoAspect );
927 AISShape->Attributes()->SetVIsoAspect( vIsoAspect );
929 // set deflection coefficient
930 // ... to avoid to small values of the coefficient, its lower value is limited
931 AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) );
935 if ( HasTexture() ) {
936 // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function
937 aImagePath = GetTexture().c_str();
938 if ( ! entry.isEmpty() ) {
939 // check that study is active
940 SalomeApp_Study* study = getActiveStudy();
942 // Store the texture in object properties for next displays
943 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) );
944 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
946 // Update properties map
947 propMap = getObjectProperties( study, entry, myViewFrame );
952 aImagePath = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
955 Handle(Image_PixMap) aPixmap;
956 if ( !aImagePath.isEmpty() )
957 aPixmap = cacheTextureFor( aImagePath, AISShape );
959 aPixmap = getDefaultTexture();
961 // apply image to shape
962 if ( !aPixmap.IsNull() ) {
963 AISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMap( new Graphic3d_Texture2Dmanual( aPixmap ) );
965 if ( displayMode == GEOM_AISShape::TexturedShape )
966 AISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn();
968 AISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOff();
971 AISShape->SetWidth( HasWidth() ?
972 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
974 // libe width from properties
975 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
977 // set top-level flag
978 AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
980 // set point marker (for vertex / compound of vertices only)
981 if ( onlyVertex || isVerticesMode ) {
982 QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
983 if ( aList.size() == 2 ) {
984 // standard marker string contains "TypeOfMarker:ScaleOfMarker"
985 int aTypeOfMarker = aList[0].toInt();
986 double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
987 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
988 anAspect->SetScale( aScaleOfMarker );
989 anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
990 anAspect->SetColor( HasColor() ?
991 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
992 (Quantity_NameOfColor)GetColor() :
993 // color from properties
994 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ) );
995 AISShape->Attributes()->SetPointAspect( anAspect );
997 else if ( aList.size() == 1 ) {
998 // custom marker string contains "IdOfTexture"
999 int textureId = aList[0].toInt();
1000 Standard_Integer aWidth, aHeight;
1001 Handle(TColStd_HArray1OfByte) aTexture =
1002 GeometryGUI::getTexture( study, textureId, aWidth, aHeight );
1003 if ( !aTexture.IsNull() ) {
1004 Handle(Prs3d_PointAspect) aTextureAspect =
1005 new Prs3d_PointAspect( HasColor() ?
1006 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1007 (Quantity_NameOfColor)GetColor() :
1008 // color from properties
1009 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
1012 AISShape->Attributes()->SetPointAspect( aTextureAspect );
1017 // set field step data
1018 AISShape->setFieldStepInfo( myFieldDataType,
1022 myFieldStepRangeMin,
1023 myFieldStepRangeMax );
1025 if ( create && !isTemporary && aMgrId != -1 ) {
1026 // set properties to the study
1027 study->setObjectProperties( aMgrId, entry, propMap );
1030 // AISShape->SetName(???); ??? necessary to set name ???
1033 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
1035 // check that actor is not null
1036 if ( !actor ) return;
1038 // check that study is active
1039 SalomeApp_Study* study = getStudy();
1040 if ( !study ) return;
1042 // set interactive object
1044 Handle( SALOME_InteractiveObject ) anIO;
1046 if ( !myIO.IsNull() ) {
1047 actor->setIO( myIO );
1050 else if ( !myName.empty() ) {
1051 // workaround to allow selection of temporary objects
1052 static int tempId = 0;
1053 anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
1054 actor->setIO( anIO );
1057 // presentation study entry (empty for temporary objects like preview)
1058 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
1059 // flag: temporary object
1060 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
1061 // currently active view window's ID (-1 if no active view)
1062 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
1064 // get presentation properties
1065 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
1068 /////////////////////////////////////////////////////////////////////////
1069 // VSR: for VTK viewer currently deflection coefficient is hardcoded
1070 // due to performance problem
1071 // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
1072 /////////////////////////////////////////////////////////////////////////
1073 if ( !actor->getTopo().IsSame( myShape ) )
1074 #ifdef LIMIT_DEFLECTION_FOR_VTK
1075 actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
1077 actor->SetShape( myShape, qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ), myType == GEOM_VECTOR );
1081 Material_Model material;
1082 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
1083 std::vector<vtkProperty*> mprops;
1084 mprops.push_back( material.getMaterialVTKProperty( true ) );
1085 mprops.push_back( material.getMaterialVTKProperty( false) );
1086 actor->SetMaterial( mprops );
1088 // set iso-lines properties
1090 // - set number of iso-lines
1091 int nbIsos[2]= { 1, 1 };
1092 if ( HasNbIsos() ) {
1093 nbIsos[0] = GetNbIsos();
1094 nbIsos[1] = GetNbIsos();
1097 QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
1098 nbIsos[0] = isos[0].toInt();
1099 nbIsos[1] = isos[1].toInt();
1101 actor->SetNbIsos( nbIsos );
1103 // - set iso-lines width
1104 actor->SetIsosWidth( HasIsosWidth() ? GetIsosWidth() : propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
1106 // - set iso-lines color
1107 if ( HasIsosColor() )
1108 c = SalomeApp_Tools::color( Quantity_Color((Quantity_NameOfColor)GetIsosColor()) );
1110 c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
1111 actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
1116 // - same color for all sub-actors
1117 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1118 actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1121 // shading color (for non-physical materials)
1122 if ( !material.isPhysical() ) {
1123 c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
1124 actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1125 actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1128 // - standalone edge color
1129 c = propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>();
1130 actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1132 c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
1133 // - shared edges color ???
1134 actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1136 c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
1137 // - free edges color ???
1138 actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
1141 c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
1142 actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
1145 // - color for edges in shading+edges mode
1146 c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
1147 actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
1149 // - color of labels (shape name)
1150 c = colorFromResources( "label_color", QColor( 255, 255, 255 ) );
1151 actor->SetLabelColor( c.redF(), c.greenF(), c.blueF() );
1154 if( HasTransparency() ) {
1155 actor->SetOpacity( 1.0 - GetTransparency() );
1157 actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
1161 actor->SetWidth( HasWidth() ?
1162 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1164 // libe width from properties
1165 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
1167 // set display vectors flag
1168 actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
1170 // set display vertices flag
1171 actor->SetVerticesMode( propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool() );
1173 // set display name flag
1174 actor->SetNameMode( propMap.value( GEOM::propertyName( GEOM::ShowName ) ).toBool() );
1177 int displayMode = HasDisplayMode() ?
1178 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
1180 // display mode from properties
1181 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
1183 // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
1184 // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
1185 // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
1186 // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
1188 if ( displayMode == 2 )
1189 // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
1190 // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
1192 actor->setDisplayMode( displayMode );
1195 actor->PickableOn();
1197 actor->PickableOff();
1199 if ( create && !isTemporary && aMgrId != -1 ) {
1200 // set properties to the study
1201 study->setObjectProperties( aMgrId, entry, propMap );
1205 //=================================================================
1207 * GEOM_Displayer::updateDimensions
1208 * Creates or renews dimension presentation for the IO.
1210 //=================================================================
1211 void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& theIO,
1212 SALOME_OCCPrs* thePrs,
1213 const gp_Ax3& theShapeLCS )
1215 SalomeApp_Study* aStudy = getStudy();
1221 if ( theIO.IsNull() )
1226 SOCC_Prs* anOccPrs = dynamic_cast<SOCC_Prs*>( thePrs );
1228 AIS_ListOfInteractive aListOfIO;
1230 anOccPrs->GetObjects( aListOfIO );
1232 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
1234 // remove outdated presentations of dimensions
1235 for ( ; aIterateIO.More(); aIterateIO.Next() )
1237 const Handle(AIS_InteractiveObject)& anIO = aIterateIO.Value();
1238 if ( !anIO->IsKind( STANDARD_TYPE( AIS_Dimension ) ) )
1243 aListOfIO.Remove( aIterateIO );
1245 if ( !aIterateIO.More() )
1251 // prepare dimension styling
1252 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1254 QColor aQColor = aResMgr->colorValue ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
1255 int aLineWidth = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
1256 QFont aFont = aResMgr->fontValue ( "Geometry", "dimensions_font", QFont("Y14.5M-2009", 14) );
1257 double anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
1258 bool isUnitsShown = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
1259 QString aUnitsLength = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
1260 QString aUnitsAngle = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
1261 bool aUseText3d = aResMgr->booleanValue( "Geometry", "dimensions_use_text3d", false );
1263 // restore dimension presentation from saved attribute or property data
1264 AIS_ListOfInteractive aRestoredDimensions;
1266 QVariant aProperty = aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1268 GEOM::propertyName( GEOM::Dimensions ),
1271 GEOMGUI_DimensionProperty aRecords;
1273 if ( aProperty.isValid() && aProperty.canConvert<GEOMGUI_DimensionProperty>() )
1275 aRecords = aProperty.value<GEOMGUI_DimensionProperty>();
1279 aRecords.LoadFromAttribute( getStudy(), theIO->getEntry() );
1282 // create up-to-date dimension presentations
1283 for ( int aPrsIt = 0; aPrsIt < aRecords.GetNumber(); ++aPrsIt )
1285 if ( !aRecords.IsVisible( aPrsIt ) )
1290 // init dimension by type
1291 Handle(AIS_Dimension) aPrs;
1292 switch( aRecords.GetType( aPrsIt ) )
1294 case GEOMGUI_DimensionProperty::DimensionType_Length :
1296 Handle(GEOM_AISLength) aLength = new GEOM_AISLength( aPrsIt );
1297 aRecords.GetRecord( aPrsIt )->AsLength()->Update( aLength, theShapeLCS );
1302 case GEOMGUI_DimensionProperty::DimensionType_Diameter :
1304 Handle(GEOM_AISDiameter) aDiam = new GEOM_AISDiameter( aPrsIt );
1305 aRecords.GetRecord( aPrsIt )->AsDiameter()->Update( aDiam, theShapeLCS );
1310 case GEOMGUI_DimensionProperty::DimensionType_Angle :
1312 Handle(GEOM_AISAngle) anAng = new GEOM_AISAngle( aPrsIt );
1313 aRecords.GetRecord( aPrsIt )->AsAngle()->Update( anAng, theShapeLCS );
1319 aPrs->SetOwner( theIO );
1321 Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
1323 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
1325 aStyle->SetCommonColor( aColor );
1326 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1327 aStyle->MakeText3d( aUseText3d );
1328 aStyle->MakeTextShaded( Standard_True );
1329 int fsize = aFont.pixelSize() != -1 ? aFont.pixelSize() : aFont.pointSize();
1330 aStyle->SetExtensionSize( fsize * 0.5 );
1331 aStyle->TextAspect()->SetFont( aFont.family().toLatin1().data() );
1332 aStyle->TextAspect()->SetHeight( fsize );
1333 aStyle->ArrowAspect()->SetLength( anArrowLength );
1334 aStyle->LineAspect()->SetWidth( aLineWidth );
1335 aStyle->SetTextHorizontalPosition( aPrs->DimensionAspect()->TextHorizontalPosition() );
1336 aStyle->SetTextVerticalPosition( aPrs->DimensionAspect()->TextVerticalPosition() );
1337 aStyle->SetArrowOrientation( aPrs->DimensionAspect()->ArrowOrientation() );
1338 aPrs->SetDimensionAspect( aStyle );
1339 aPrs->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
1340 aPrs->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
1341 aPrs->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
1343 if ( aPrs->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
1345 // show degree symbol for dimension instead of label "deg"
1346 if ( aUnitsAngle == "deg" )
1348 aPrs->SetSpecialSymbol(0xB0);
1349 aPrs->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
1350 aStyle->MakeUnitsDisplayed(Standard_False);
1354 aPrs->SetDisplaySpecialSymbol(AIS_DSS_No);
1355 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1360 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1363 aListOfIO.Append( aPrs );
1366 // update presentation
1369 for ( aIterateIO.Initialize( aListOfIO ); aIterateIO.More(); aIterateIO.Next() )
1371 anOccPrs->AddObject( aIterateIO.Value() );
1375 //=================================================================
1377 * GEOM_Displayer::Erase
1378 * Calls Erase() method for each object in the given list
1380 //=================================================================
1381 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
1383 const bool updateViewer )
1385 SALOME_ListIteratorOfListIO Iter( theIOList );
1386 for ( ; Iter.More(); Iter.Next() )
1387 Erase( Iter.Value(), forced, false );
1393 //=================================================================
1395 * GEOM_Displayer::Redisplay
1396 * Calls Redisplay() method for each object in the given list
1398 //=================================================================
1399 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1400 const bool updateViewer,
1401 const bool checkActiveViewer )
1403 SALOME_ListIteratorOfListIO Iter( theIOList );
1404 for ( ; Iter.More(); Iter.Next() )
1405 Redisplay( Iter.Value(), false, checkActiveViewer );
1411 //=================================================================
1413 * GEOM_Displayer::Redisplay
1414 * Calls Redisplay() method for each object in the given list
1416 //=================================================================
1417 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1418 const bool theUpdateViewer,
1419 SALOME_View* theViewFrame )
1421 SALOME_ListIteratorOfListIO anIter( theIOList );
1422 for ( ; anIter.More(); anIter.Next() )
1424 Redisplay( anIter.Value(), false, theViewFrame );
1427 if ( theUpdateViewer )
1433 //=================================================================
1435 * GEOM_Displayer::Update
1436 * Update OCC presentaion
1437 * [ Reimplemented from SALOME_Displayer ]
1439 //=================================================================
1440 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
1442 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
1443 SalomeApp_Study* study = getStudy();
1445 if ( !occPrs || myShape.IsNull() || !study )
1448 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1451 // specific processing for local coordinate system presentation
1454 TopoDS_Face aFace = TopoDS::Face( myShape );
1455 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1456 if ( !aPlane.IsNull() )
1458 gp_Ax3 aPos = aPlane->Pln().Position();
1459 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1461 Handle(GEOM_AISTrihedron) aTrh;
1463 if ( occPrs->IsNull() )
1465 // new presentation is being created
1466 aTrh = new GEOM_AISTrihedron( aPlc );
1467 occPrs->AddObject( aTrh );
1471 // presentation is being updated
1472 AIS_ListOfInteractive aList;
1473 occPrs->GetObjects( aList );
1474 AIS_ListIteratorOfListOfInteractive anIter( aList );
1475 for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
1476 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
1480 if ( !aTrh.IsNull() ) {
1481 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1483 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1484 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1486 aTrh->SetWidth( GetWidth() );
1488 if ( !myIO.IsNull() )
1490 aTrh->setIO( myIO );
1491 aTrh->SetOwner( myIO );
1493 aTrh->SetComponent( aPlc );
1494 aTrh->SetToUpdate();
1496 occPrs->SetToActivate( ToActivate() );
1502 // processing for usual geometry presentation
1505 // if presentation is empty we try to create new one
1506 if ( occPrs->IsNull() )
1508 // create presentation (specific for vectors)
1509 Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1510 : new GEOM_AISShape ( myShape, "" );
1512 if( myType == GEOM_FIELD_STEP )
1513 AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight );
1514 // update shape properties
1515 updateShapeProperties( AISShape, true );
1517 // add shape to the presentation
1518 occPrs->AddObject( AISShape );
1520 // In accordance with ToActivate() value object will be activated/deactivated
1521 // when it will be displayed
1522 occPrs->SetToActivate( ToActivate() );
1524 if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1525 // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1527 // create additional wireframe shape
1528 Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1529 aWirePrs->SetWidth(AISShape->Width());
1530 if ( !myIO.IsNull() ) {
1531 aWirePrs->setIO( myIO );
1532 aWirePrs->SetOwner( myIO );
1535 // add shape to the presentation
1536 occPrs->AddObject( aWirePrs );
1539 // if presentation is found -> set again shape for it
1542 AIS_ListOfInteractive IOList;
1543 occPrs->GetObjects( IOList );
1544 AIS_ListIteratorOfListOfInteractive Iter( IOList );
1545 for ( ; Iter.More(); Iter.Next() )
1547 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1548 if ( AISShape.IsNull() )
1551 // re-set shape (it might be changed)
1552 if ( AISShape->Shape() != myShape )
1553 AISShape->Set( myShape );
1555 // update shape properties
1556 updateShapeProperties( AISShape, false );
1559 AISShape->UpdateSelection();
1560 AISShape->SetToUpdate();
1564 updateDimensions( myIO, occPrs, gp_Ax3().Transformed( myShape.Location().Transformation() ) );
1568 //=================================================================
1570 * GEOM_Displayer::Update
1571 * Update VTK presentaion
1572 * [ Reimplemented from SALOME_Displayer ]
1574 //=================================================================
1575 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1577 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1578 SalomeApp_Study* study = getStudy();
1580 if ( !vtkPrs || myShape.IsNull() || !study )
1583 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1586 // specific processing for local coordinate system presentation
1589 TopoDS_Face aFace = TopoDS::Face( myShape );
1590 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1591 if ( !aPlane.IsNull() ) {
1592 gp_Ax3 aPos = aPlane->Pln().Position();
1593 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1595 GEOM_VTKTrihedron* aTrh = 0;
1597 if ( vtkPrs->IsNull() ) {
1598 // new presentation is being created
1599 aTrh = GEOM_VTKTrihedron::New();
1600 vtkPrs->AddObject( aTrh );
1603 // presentation is being updated
1604 vtkActorCollection* actors = vtkPrs->GetObjects();
1606 actors->InitTraversal();
1607 vtkActor* a = actors->GetNextActor();
1608 while ( a && !aTrh ) {
1609 aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1610 a = actors->GetNextActor();
1616 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1618 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1619 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1621 #ifdef VTK_TRIHEDRON_WIDTH
1623 // VSR: currently isn't supported
1625 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1627 aTrh->SetWidth( GetWidth() );
1630 if ( !myIO.IsNull() )
1631 aTrh->setIO( myIO );
1633 aTrh->SetPlacement( aPlc );
1640 // processing for usual geometry presentation
1643 // if presentation is empty we try to create new one
1644 if ( vtkPrs->IsNull() )
1647 GEOM_Actor* actor = GEOM_Actor::New();
1648 // update actor properties
1649 updateActorProperties( actor, true );
1650 // add actor to the presentation
1651 vtkPrs->AddObject( actor );
1654 // presentation is being updated
1655 vtkActorCollection* actors = vtkPrs->GetObjects();
1657 actors->InitTraversal();
1658 vtkActor* a = actors->GetNextActor();
1660 GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1662 // update actor properties
1663 updateActorProperties( actor, false );
1664 a = actors->GetNextActor();
1672 //=================================================================
1674 * GEOM_Displayer::BuildPrs
1675 * Build presentation accordint to the current viewer type
1677 //=================================================================
1678 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1680 if ( theObj->_is_nil() )
1683 myViewFrame = GetActiveView();
1684 if ( myViewFrame == 0 )
1687 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1692 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1693 myType = theObj->GetType();
1695 // Update presentation
1701 //=================================================================
1703 * GEOM_Displayer::BuildPrs
1704 * Build presentation accordint to the current viewer type
1706 //=================================================================
1707 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1709 myViewFrame = GetActiveView();
1710 if ( theShape.IsNull() || myViewFrame == 0 )
1713 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1718 setShape( theShape );
1726 //=================================================================
1728 * GEOM_Displayer::buildPresentation
1729 * Builds/finds object's presentation for the current viewer
1730 * Calls corresponding Update() method by means of double dispatch
1733 //=================================================================
1734 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1735 SALOME_View* theViewFrame )
1737 SALOME_Prs* prs = 0;
1740 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1744 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1747 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1748 theIO->setEntry( entry.toLatin1().constData() );
1749 if ( !theIO.IsNull() )
1751 // set interactive object
1753 // Find SOBject (because shape should be published previously)
1754 SUIT_Session* session = SUIT_Session::session();
1755 SUIT_Application* app = session->activeApplication();
1758 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1761 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1764 // get CORBA reference to data object
1765 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1766 if ( !CORBA::is_nil( object ) )
1768 // downcast to GEOM base object
1769 GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
1770 if ( !GeomBaseObject->_is_nil() )
1772 myType = GeomBaseObject->GetType();
1774 // downcast to GEOM object
1775 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
1776 if ( myType == GEOM_FIELD_STEP )
1778 // get the GEOM object from the field's shape
1779 GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
1780 if ( !GeomFieldStep->_is_nil() )
1782 GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
1783 if ( !GeomField->_is_nil() )
1784 GeomObject = GeomField->GetShape();
1787 // read the field step information
1788 readFieldStepInfo( GeomFieldStep );
1791 if ( !GeomObject->_is_nil() )
1793 CORBA::String_var name = GeomObject->GetName();
1794 theIO->setName( name );
1795 // finally set shape
1796 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1804 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1810 //=================================================================
1812 * GEOM_Displayer::buildSubshapePresentation
1813 * Builds/finds object's presentation for the current viewer
1814 * Calls corresponding Update() method by means of double dispatch
1815 * For not published objects (for Mantis issue 0020435)
1817 //=================================================================
1818 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1819 const QString& entry,
1820 SALOME_View* theViewFrame)
1822 SALOME_Prs* prs = 0;
1825 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1829 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1832 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1833 theIO->setEntry(entry.toLatin1().constData());
1834 if (!theIO.IsNull())
1836 // set interactive object
1838 // finally set shape
1840 myType = GEOM_SUBSHAPE;
1842 UpdatePrs(prs); // Update presentation by using of the double dispatch
1848 //=================================================================
1850 * GEOM_Displayer::internalReset
1851 * Resets internal data
1854 //=================================================================
1855 void GEOM_Displayer::internalReset()
1860 myFieldDataType = GEOM::FDT_Double;
1861 myFieldDimension = 0;
1862 myFieldStepData.clear();
1863 myFieldStepName.Clear();
1864 myFieldStepRangeMin = 0;
1865 myFieldStepRangeMax = 0;
1868 //=================================================================
1870 * GEOM_Displayer::LocalSelection
1871 * Activate selection of CAD shapes with activisation of selection
1872 * of their sub-shapes (with opened local context for OCC viewer)
1874 //=================================================================
1875 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const std::list<int> modes )
1877 SUIT_Session* session = SUIT_Session::session();
1878 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1882 LightApp_SelectionMgr* sm = app->selectionMgr();
1884 // remove all filters from selection
1887 SALOME_View* vf = GetActiveView();
1889 if (!theIO.IsNull() && !vf->isVisible(theIO))
1891 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1892 vf->LocalSelection( prs, modes );
1893 delete prs; // delete presentation because displayer is its owner
1897 //=================================================================
1899 * GEOM_Displayer::LocalSelection
1900 * Activate selection of CAD shapes with activisation of selection
1901 * of their sub-shapes (with opened local context for OCC viewer)
1903 //=================================================================
1904 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1906 std::list<int> modes;
1907 modes.push_back( theMode );
1908 LocalSelection( theIO, modes );
1911 //=================================================================
1913 * GEOM_Displayer::globalSelection
1914 * Activate selection of CAD shapes without activisation of selection
1915 * of their sub-shapes (without opened local context for OCC viewer)
1917 //=================================================================
1918 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1920 TColStd_MapOfInteger aModes;
1921 aModes.Add( theMode );
1922 GlobalSelection( aModes, update );
1925 //=================================================================
1927 * GEOM_Displayer::globalSelection
1928 * Activate selection of CAD shapes without activisation of selection
1929 * of their sub-shapes (without opened local context for OCC viewer)
1931 //=================================================================
1932 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1933 const bool update, const QList<int>* theSubShapes )
1935 SUIT_Session* session = SUIT_Session::session();
1936 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1940 SALOME_View* vf = GetActiveView();
1944 // Close local context
1945 vf->GlobalSelection( update );
1947 // Set selection filters in accordance with current mode
1948 LightApp_SelectionMgr* sm = app->selectionMgr();
1952 // Remove from selection temporary objects if necessary
1953 if ( !theModes.Contains( GEOM_PREVIEW ) )
1954 clearTemporary( sm );
1956 //@ aSel->ClearIndex();
1960 // Remove filters from AIS_InteractiveContext
1961 Handle(AIS_InteractiveContext) ic;
1962 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1965 ic = viewer->getAISContext();
1967 ic->RemoveFilters();
1970 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1973 SUIT_SelectionFilter* aFilter;
1974 if ( theModes.Extent() == 1 )
1976 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1978 if ( aMode == GEOM_COMPOUNDFILTER )
1979 aFilter = getComplexFilter( theSubShapes );
1981 aFilter = getFilter( aMode );
1983 else if ( theModes.Extent() > 1 )
1985 TColStd_MapOfInteger aTopAbsModes;
1986 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1987 QList<SUIT_SelectionFilter*> aListOfFilters;
1988 for ( ; anIter.More(); anIter.Next() )
1990 SUIT_SelectionFilter* aFilter;
1991 int aMode = anIter.Key();
1992 if ( aMode == GEOM_COMPOUNDFILTER )
1993 aFilter = getComplexFilter( theSubShapes );
1995 aFilter = getFilter( aMode );
1998 aListOfFilters.append( aFilter );
2001 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
2008 sm->installFilter( aFilter );
2011 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
2012 ic->AddFilter( anOCCFilter );
2017 //=================================================================
2019 * GEOM_Displayer::LocalSelection
2020 * Activate selection of CAD shapes with activisation of selection
2021 * of their sub-shapes (with opened local context for OCC viewer)
2023 //=================================================================
2024 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const std::list<int> modes )
2026 SALOME_ListIteratorOfListIO Iter( theIOList );
2027 for ( ; Iter.More(); Iter.Next() )
2028 LocalSelection( Iter.Value(), modes );
2031 //=================================================================
2033 * GEOM_Displayer::LocalSelection
2034 * Activate selection of CAD shapes with activisation of selection
2035 * of their sub-shapes (with opened local context for OCC viewer)
2037 //=================================================================
2038 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
2040 std::list<int> modes;
2041 modes.push_back( theMode );
2042 LocalSelection( theIOList, modes );
2045 //=================================================================
2047 * GEOM_Displayer::BeforeDisplay
2048 * Called before displaying of pars. Close local context
2049 * [ Reimplemented from SALOME_Displayer ]
2051 //=================================================================
2052 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
2054 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
2057 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
2060 if ( ic->HasOpenedContext() )
2061 ic->CloseAllContexts(Standard_True);
2066 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
2070 // visualize annotations for displayed presentation
2071 SUIT_Session* session = SUIT_Session::session();
2072 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2073 GeometryGUI* aModule = dynamic_cast<GeometryGUI*>( anApp->activeModule() );
2075 if ( !myIsRedisplayed ) {
2076 aModule->GetAnnotationMgr()->DisplayVisibleAnnotations(QString(p->GetEntry()), dynamic_cast<SOCC_Viewer*>( v ));
2078 aModule->GetAnnotationMgr()->UpdateVisibleAnnotations(QString(p->GetEntry()), dynamic_cast<SOCC_Viewer*>( v ));
2083 void GEOM_Displayer::BeforeErase( SALOME_View* v, const SALOME_OCCPrs* p )
2085 LightApp_Displayer::BeforeErase( v, p );
2086 releaseTextures( p );
2089 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
2091 LightApp_Displayer::AfterErase( v, p );
2094 if ( !myIsRedisplayed ) {
2095 // hide annotations for erased presentation
2096 SUIT_Session* session = SUIT_Session::session();
2097 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2098 GeometryGUI* aModule = dynamic_cast<GeometryGUI*>( anApp->activeModule() );
2100 aModule->GetAnnotationMgr()->EraseVisibleAnnotations(QString(p->GetEntry()), dynamic_cast<SOCC_Viewer*>( v ));
2104 //=================================================================
2106 * GEOM_Displayer::SetColor
2107 * Set color for shape displaying. If it is equal -1 then default color is used.
2108 * Available values are from Quantity_NameOfColor enumeration
2110 //=================================================================
2111 void GEOM_Displayer::SetColor( const int color )
2118 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
2122 int GEOM_Displayer::GetColor() const
2127 bool GEOM_Displayer::HasColor() const
2129 return myColor != -1;
2132 void GEOM_Displayer::UnsetColor()
2136 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2137 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
2138 myShadingColor = SalomeApp_Tools::color( col );
2141 //=================================================================
2143 * GEOM_Displayer::SetTransparency
2144 * Set transparency for shape displaying.
2146 //=================================================================
2147 double GEOM_Displayer::SetTransparency( const double transparency )
2149 double prevTransparency = myTransparency;
2150 myTransparency = transparency;
2151 return prevTransparency;
2154 //=================================================================
2156 * GEOM_Displayer::GetTransparency
2157 * Get transparency for shape displaying.
2159 //=================================================================
2160 double GEOM_Displayer::GetTransparency() const
2162 return myTransparency;
2165 //=================================================================
2167 * GEOM_Displayer::HasTransparency
2168 * Check if transparency for shape displaying is set.
2170 //=================================================================
2171 bool GEOM_Displayer::HasTransparency() const
2173 return myTransparency >= 0;
2176 //=================================================================
2178 * GEOM_Displayer::UnsetTransparency
2179 * Unset transparency for shape displaying.
2181 //=================================================================
2182 double GEOM_Displayer::UnsetTransparency()
2184 return SetTransparency( -1 );
2187 //=================================================================
2189 * GEOM_Displayer::SetTexture
2191 //=================================================================
2192 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
2194 myTexture = texureFileName;
2197 bool GEOM_Displayer::HasTexture() const
2199 return myTexture != "";
2202 std::string GEOM_Displayer::GetTexture() const
2207 //=================================================================
2209 * GEOM_Displayer::SetWidth
2210 * Set width of shape displaying. If it is equal -1 then default width is used.
2212 //=================================================================
2213 void GEOM_Displayer::SetWidth( const double width )
2218 double GEOM_Displayer::GetWidth() const
2223 bool GEOM_Displayer::HasWidth() const
2225 return myWidth != -1;
2228 void GEOM_Displayer::UnsetWidth()
2233 int GEOM_Displayer::GetIsosWidth() const
2238 void GEOM_Displayer::SetIsosWidth(const int width)
2240 myIsosWidth = width;
2243 bool GEOM_Displayer::HasIsosWidth() const
2245 return myIsosWidth != -1;
2248 int GEOM_Displayer::SetNbIsos( const int nbIsos )
2250 int prevNbIsos = myNbIsos;
2255 int GEOM_Displayer::UnsetNbIsos()
2257 return SetNbIsos( -1 );
2260 int GEOM_Displayer::GetNbIsos() const
2265 bool GEOM_Displayer::HasNbIsos() const
2267 return myNbIsos >= 0;
2270 int GEOM_Displayer::SetIsosColor( const int color )
2272 int prevColor = myIsosColor;
2273 myIsosColor = color;
2277 int GEOM_Displayer::GetIsosColor() const
2282 bool GEOM_Displayer::HasIsosColor() const
2284 return myIsosColor != -1;
2287 int GEOM_Displayer::UnsetIsosColor()
2289 return SetIsosColor( -1 );
2292 //=================================================================
2294 * GEOM_Displayer::SetToActivate
2295 * This method is used for activisation/deactivisation of objects to be displayed
2297 //=================================================================
2298 void GEOM_Displayer::SetToActivate( const bool toActivate )
2300 myToActivate = toActivate;
2302 bool GEOM_Displayer::ToActivate() const
2304 return myToActivate;
2307 //=================================================================
2309 * GEOM_Displayer::clearTemporary
2310 * Removes from selection temporary objects
2312 //=================================================================
2313 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
2315 SALOME_ListIO selected, toSelect;
2316 theSelMgr->selectedObjects( selected );
2318 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
2319 Handle(SALOME_InteractiveObject) io = it.Value();
2320 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
2321 toSelect.Append( it.Value() );
2324 theSelMgr->setSelectedObjects( toSelect, true );
2327 void GEOM_Displayer::SetName( const char* theName )
2332 void GEOM_Displayer::UnsetName()
2337 SalomeApp_Study* GEOM_Displayer::getStudy() const
2339 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2342 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
2347 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
2352 void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
2353 const int theFieldDimension,
2354 const QList<QVariant>& theFieldStepData,
2355 const TCollection_AsciiString& theFieldStepName,
2356 const double theFieldStepRangeMin,
2357 const double theFieldStepRangeMax )
2359 myFieldDataType = theFieldDataType;
2360 myFieldDimension = theFieldDimension;
2361 myFieldStepData = theFieldStepData;
2362 myFieldStepName = theFieldStepName;
2363 myFieldStepRangeMin = theFieldStepRangeMin;
2364 myFieldStepRangeMax = theFieldStepRangeMax;
2367 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
2369 _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
2370 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
2371 GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
2372 GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
2373 return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
2374 (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
2377 int GEOM_Displayer::SetDisplayMode( const int theMode )
2379 int aPrevMode = myDisplayMode;
2380 if ( theMode != -1 ) {
2381 myDisplayMode = theMode;
2382 myHasDisplayMode = true;
2390 int GEOM_Displayer::GetDisplayMode() const
2392 return myDisplayMode;
2395 int GEOM_Displayer::UnsetDisplayMode()
2397 int aPrevMode = myDisplayMode;
2398 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2399 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
2400 myHasDisplayMode = false;
2404 bool GEOM_Displayer::HasDisplayMode() const
2406 return myHasDisplayMode;
2409 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
2411 static QList<QColor> colors;
2413 if ( colors.isEmpty() ) {
2415 for (int s = 0; s < 2 ; s++)
2417 for (int v = 100; v >= 40; v = v - 20)
2419 for (int h = 0; h < 359 ; h = h + 60)
2421 colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
2427 static int currentColor = randomize( colors.size() );
2429 SALOMEDS::Color color;
2430 color.R = (double)colors[currentColor].red() / 255.0;
2431 color.G = (double)colors[currentColor].green() / 255.0;
2432 color.B = (double)colors[currentColor].blue() / 255.0;
2434 currentColor = (currentColor+1) % colors.count();
2439 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
2442 int aTolerance = 64;
2443 int anIterations = 0;
2449 if( anIterations % aPeriod == 0 )
2452 if( aTolerance < 1 )
2455 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
2457 aHue = (int)( 360.0 * rand() / RAND_MAX );
2458 //std::cout << "Hue = " << aHue << std::endl;
2460 //std::cout << "Auto colors : ";
2462 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
2463 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
2464 for( ; it != itEnd; ++it )
2466 SALOMEDS::Color anAutoColor = *it;
2467 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
2470 aQColor.getHsv( &h, &s, &v );
2471 //std::cout << h << " ";
2472 if( abs( h - aHue ) < aTolerance )
2475 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
2479 //std::cout << std::endl;
2485 //std::cout << "Hue of the returned color = " << aHue << std::endl;
2487 aColor.setHsv( aHue, 255, 255 );
2489 SALOMEDS::Color aSColor;
2490 aSColor.R = (double)aColor.red() / 255.0;
2491 aSColor.G = (double)aColor.green() / 255.0;
2492 aSColor.B = (double)aColor.blue() / 255.0;
2497 PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
2498 const QString& entry,
2501 // get default properties for the explicitly specified default view type
2502 PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
2504 if ( study && view ) {
2505 SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
2506 SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
2507 int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
2509 if ( viewModel && viewId != -1 ) {
2510 // get properties from the study
2511 PropMap storedMap = study->getObjectProperties( viewId, entry );
2512 // overwrite default properties from stored ones (that are specified)
2513 for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
2514 if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
2515 propMap.insert( GEOM::propertyName( (GEOM::Property)prop ),
2516 storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
2518 // ... specific processing for color
2519 // ... current implementation is to use same stored color for all aspects
2520 // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2521 if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2522 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2523 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2524 propMap.insert( GEOM::propertyName( GEOM::LineColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2525 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2526 propMap.insert( GEOM::propertyName( GEOM::PointColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2529 if ( !entry.isEmpty() ) {
2530 // get CORBA reference to geom object
2531 _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
2533 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
2534 if ( !CORBA::is_nil( object ) ) {
2535 GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
2536 if ( !CORBA::is_nil( geomObject ) ) { // to check
2537 // check that geom object has color properly set
2538 bool hasColor = false;
2539 SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
2540 // set color from geometry object (only once, if it is not yet set in GUI)
2541 // current implementation is to use same color for all aspects
2542 // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2543 if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2544 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
2545 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), objColor );
2546 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
2547 propMap.insert( GEOM::propertyName( GEOM::LineColor ), objColor );
2548 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), objColor );
2549 propMap.insert( GEOM::propertyName( GEOM::PointColor ), objColor );
2551 // check that object has point marker properly set
2552 GEOM::marker_type mType = geomObject->GetMarkerType();
2553 GEOM::marker_size mSize = geomObject->GetMarkerSize();
2554 int mTextureId = geomObject->GetMarkerTexture();
2555 bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) ||
2556 ( mType == GEOM::MT_USER && mTextureId > 0 );
2557 // set point marker from geometry object (only once, if it is not yet set in GUI)
2558 if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
2559 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
2561 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2562 QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
2564 else if ( mType == GEOM::MT_USER ) {
2566 propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
2578 PropMap GEOM_Displayer::getDefaultPropertyMap()
2582 // get resource manager
2583 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2585 // fill in the properties map with default values
2587 // - visibility (false by default)
2588 propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
2590 // - nb isos (take default value from preferences)
2591 propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
2592 QString( "%1%2%3" ).
2593 arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
2594 arg( GEOM::subSectionSeparator() ).
2595 arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
2597 // - transparency (opacity = 1-transparency)
2598 propMap.insert( GEOM::propertyName( GEOM::Transparency ),
2599 resMgr->integerValue( "Geometry", "transparency", 0 ) / 100. );
2601 // - display mode (take default value from preferences)
2602 propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
2603 resMgr->integerValue( "Geometry", "display_mode", 0 ) );
2605 // - show edges direction flag (false by default)
2606 propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
2608 // - show vertices flag (false by default)
2609 propMap.insert( GEOM::propertyName( GEOM::Vertices ), false );
2611 // - show name flag (false by default)
2612 propMap.insert( GEOM::propertyName( GEOM::ShowName ), false );
2614 // - shading color (take default value from preferences)
2615 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
2616 colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
2618 // - wireframe color (take default value from preferences)
2619 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
2620 colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
2622 // - standalone edges color (take default value from preferences)
2623 propMap.insert( GEOM::propertyName( GEOM::LineColor ),
2624 colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
2626 // - free boundaries color (take default value from preferences)
2627 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
2628 colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
2630 // - points color (take default value from preferences)
2631 propMap.insert( GEOM::propertyName( GEOM::PointColor ),
2632 colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
2634 // - isos color (take default value from preferences)
2635 propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
2636 colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
2638 // - outlines color (take default value from preferences)
2639 propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
2640 colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
2642 // - deflection coefficient (take default value from preferences)
2643 propMap.insert( GEOM::propertyName( GEOM::Deflection ),
2644 resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
2646 // - material (take default value from preferences)
2647 Material_Model material;
2648 material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
2649 propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
2651 // - edge width (take default value from preferences)
2652 propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
2653 resMgr->integerValue( "Geometry", "edge_width", 1 ) );
2655 // - isos width (take default value from preferences)
2656 propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
2657 resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
2659 // - point marker (take default value from preferences)
2660 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2661 QString( "%1%2%3" ).
2662 arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
2663 arg( GEOM::subSectionSeparator() ).
2664 arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2666 // - top-level flag (false by default)
2667 propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2672 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2673 SALOMEDS::Color aSColor;
2676 SUIT_Session* session = SUIT_Session::session();
2677 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2679 if ( app && !theGeomObject->_is_nil()) {
2680 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2683 _PTR(Study) aStudy = study->studyDS();
2684 aSColor = theGeomObject->GetColor();
2685 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2687 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2688 bool general_autocolor = true;
2689 #else // auto-color for groups only
2690 bool general_autocolor = false;
2691 #endif // GENERAL_AUTOCOLOR
2692 if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2693 GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2694 if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2695 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2696 aSColor = getPredefinedUniqueColor();
2698 #else // old algorithm for auto-colors
2699 QList<SALOMEDS::Color> aReservedColors;
2700 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2701 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2702 if ( aMainSObject ) {
2703 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2704 for ( ; it->More(); it->Next() ) {
2705 _PTR(SObject) aChildSObject( it->Value() );
2706 GEOM::GEOM_Object_var aChildObject =
2707 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2708 if ( CORBA::is_nil( aChildObject ) )
2711 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2712 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2713 aReservedColors.append( aReservedColor );
2716 aSColor = getUniqueColor( aReservedColors );
2718 #endif // SIMPLE_AUTOCOLOR
2728 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2729 const bool eraseOnlyChildren) {
2730 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2734 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2738 LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2743 // Erase from all views
2744 QList<SALOME_View*> views;
2746 ViewManagerList vmans = app->viewManagers();
2747 SUIT_ViewManager* vman;
2748 foreach ( vman, vmans ) {
2749 SUIT_ViewModel* vmod = vman->getViewModel();
2750 view = dynamic_cast<SALOME_View*> ( vmod );
2752 views.append( view );
2755 if( views.count() == 0 )
2758 //Erase childrens w/o update views
2759 DataObjectList listObj = parent->children( true );
2760 SUIT_DataObject* obj;
2761 foreach( obj, listObj ) {
2762 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2764 foreach ( view, views ) {
2765 Handle(SALOME_InteractiveObject) anIO =
2766 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2767 Erase(anIO, false, false, view);
2771 //Erase parent with view update or repaint views
2772 foreach ( view, views ) {
2773 if(!eraseOnlyChildren)
2774 Erase(theIO, false, true, view);
2780 void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
2782 if( theGeomFieldStep->_is_nil() )
2785 GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
2786 if( aGeomField->_is_nil() )
2789 GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
2790 if( aGeomFieldShape->_is_nil() )
2793 TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
2794 TCollection_AsciiString aFieldName( aGeomField->GetName() );
2795 TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
2797 aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
2799 GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
2801 int aFieldDimension = aGeomField->GetDimension();
2803 GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
2804 int aFieldNbComponents = aFieldComponents->length();
2806 QList<QVariant> aFieldStepData;
2807 if( aFieldDataType == GEOM::FDT_Bool )
2809 GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
2810 if ( !aGeomBoolFieldStep->_is_nil() )
2812 GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
2813 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2814 aFieldStepData << (bool)aValues[i];
2817 else if( aFieldDataType == GEOM::FDT_Int )
2819 GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
2820 if ( !aGeomIntFieldStep->_is_nil() )
2822 GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
2823 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2824 aFieldStepData << (qlonglong)aValues[i];
2827 else if( aFieldDataType == GEOM::FDT_Double )
2829 GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
2830 if ( !aGeomDoubleFieldStep->_is_nil() )
2832 GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
2833 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2834 aFieldStepData << (double)aValues[i];
2837 else if( aFieldDataType == GEOM::FDT_String )
2839 GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
2840 if ( !aGeomStringFieldStep->_is_nil() )
2842 GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
2843 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2844 aFieldStepData << QString( aValues[i] );
2848 double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
2849 aFieldStepData = groupFieldData( aFieldStepData,
2851 aFieldDataType == GEOM::FDT_String,
2853 aFieldStepRangeMax );
2855 setFieldStepInfo( aFieldDataType,
2860 aFieldStepRangeMax );
2863 QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
2864 const int theFieldNbComponents,
2865 const bool theIsString,
2866 double& theFieldStepRangeMin,
2867 double& theFieldStepRangeMax )
2869 QList<QVariant> aResultList;
2870 theFieldStepRangeMin = 0;
2871 theFieldStepRangeMax = 0;
2873 if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
2876 int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
2878 QList<QVariant> aGroupedList;
2880 bool anIsBoolean = false;
2881 for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
2884 QStringList aStringList;
2886 int aBaseIndex = aSubShape * theFieldNbComponents;
2887 for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
2889 int anIndex = aComponent + aBaseIndex;
2891 const QVariant& aVariant = theFieldStepData[ anIndex ];
2894 if( aVariant.type() == QVariant::String )
2895 aStringList << aVariant.toString();
2900 if( aVariant.type() == QVariant::Bool )
2902 aValue = aVariant.toBool() ? 1.0 : 0.0;
2908 if( aVariant.type() == QVariant::LongLong )
2909 aValue = double( aVariant.toLongLong() );
2910 else if( aVariant.type() == QVariant::Double )
2911 aValue = aVariant.toDouble();
2912 aNorm += aValue * aValue;
2918 aGroupedList << aStringList.join( "\n" );
2922 aNorm /= theFieldNbComponents;
2924 aNorm = pow( aNorm, 0.5 );
2926 if( aGroupedList.isEmpty() )
2927 theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
2930 theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
2931 theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
2934 aGroupedList << aNorm;
2940 theFieldStepRangeMin = 0.0;
2941 theFieldStepRangeMax = 1.0;
2944 SUIT_Session* session = SUIT_Session::session();
2945 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2946 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2948 QListIterator<QVariant> anIter( aGroupedList );
2949 while( anIter.hasNext() )
2951 const QVariant& aVariant = anIter.next();
2953 aResultList << aVariant;
2957 Quantity_Color aColor;
2958 if( AIS_ColorScale::FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2959 aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
2960 aResultList << aQColor;
2966 void GEOM_Displayer::UpdateColorScale()
2968 if ( !myUpdateColorScale )
2971 SUIT_Session* session = SUIT_Session::session();
2972 SUIT_Application* app = session->activeApplication();
2975 Handle(SALOME_InteractiveObject) io = myApp->selectionMgr()->soleSelectedObject();
2977 QList<SUIT_ViewWindow*> windows = app->desktop()->windows();
2978 foreach( SUIT_ViewWindow* window, windows )
2980 OCCViewer_ViewWindow* occWindow = dynamic_cast<OCCViewer_ViewWindow*>( window );
2981 if ( !occWindow ) continue;
2982 if ( !occWindow->getViewManager() ) continue;
2983 if ( !window->getViewManager() ) continue;
2984 if ( !window->getViewManager()->getViewModel() ) continue;
2985 SOCC_Viewer* view = dynamic_cast<SOCC_Viewer*>( window->getViewManager()->getViewModel() );
2986 if ( !view ) continue;
2987 Handle(V3d_Viewer) viewer = view->getViewer3d();
2988 if ( !io.IsNull() && view->isVisible( io ) )
2990 bool visible = false;
2991 SOCC_Prs* prs = dynamic_cast<SOCC_Prs*>( view->CreatePrs( io->getEntry() ) );
2994 AIS_ListOfInteractive presentations;
2995 prs->GetObjects( presentations );
2996 AIS_ListIteratorOfListOfInteractive iter( presentations );
2997 for ( ; iter.More(); iter.Next() )
2999 Handle(GEOM_AISShape) shape = Handle(GEOM_AISShape)::DownCast( iter.Value() );
3000 if ( shape.IsNull() ) continue;
3001 GEOM::field_data_type fieldDataType;
3003 QList<QVariant> fieldStepData;
3004 TCollection_AsciiString fieldStepName;
3005 Standard_Real fieldStepRangeMin, fieldStepRangeMax;
3006 shape->getFieldStepInfo( fieldDataType, fieldDimension, fieldStepData,
3007 fieldStepName, fieldStepRangeMin, fieldStepRangeMax );
3008 visible = !fieldStepData.isEmpty() && fieldDataType != GEOM::FDT_String;
3011 SUIT_Session* session = SUIT_Session::session();
3012 SUIT_ResourceMgr* resMgr = session->resourceMgr();
3014 Standard_Real xPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
3015 Standard_Real yPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
3016 Standard_Real width = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
3017 Standard_Real height = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
3018 Standard_Integer textHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
3019 Standard_Integer nbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
3021 Standard_Integer viewWidth = 0, viewHeight = 0;
3022 occWindow->getView(0)->getViewPort()->getView()->Window()->Size( viewWidth, viewHeight );
3024 Handle(AIS_ColorScale) colorScale = view->getColorScale();
3026 colorScale->SetPosition( viewWidth * xPos, viewHeight * yPos );
3027 colorScale->SetBreadth( viewWidth * width );
3028 colorScale->SetHeight( viewHeight * height );
3029 colorScale->SetRange( fieldStepRangeMin, fieldStepRangeMax );
3030 colorScale->SetNumberOfIntervals( fieldDataType == GEOM::FDT_Bool ? 2 : nbIntervals );
3031 colorScale->SetTextHeight( textHeight );
3032 colorScale->SetTitle( fieldStepName );
3036 view->setColorScaleShown( visible );
3037 } // if ( view->isVisible( io ) )
3040 view->setColorScaleShown( false );
3042 } // foreach( SUIT_ViewWindow* window, windows )
3045 bool GEOM_Displayer::SetUpdateColorScale( bool toUpdate ) // IPAL54049
3047 bool previous = myUpdateColorScale;
3048 myUpdateColorScale = toUpdate;
3049 if ( myUpdateColorScale && !previous )