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 myColorScale = new AIS_ColorScale;
514 myColorScale->SetZLayer (Graphic3d_ZLayerId_TopOSD);
515 myColorScale->SetTransformPersistence (
516 Graphic3d_TransformPers::FromDeprecatedParams(Graphic3d_TMF_2d, gp_Pnt (-1,-1,0)));
518 myFieldDataType = GEOM::FDT_Double;
519 myFieldDimension = 0;
520 myFieldStepRangeMin = 0;
521 myFieldStepRangeMax = 0;
524 //=================================================================
526 * GEOM_Displayer::~GEOM_Displayer
529 //=================================================================
530 GEOM_Displayer::~GEOM_Displayer()
534 //=================================================================
536 * GEOM_Displayer::Display
537 * Display interactive object in the current viewer
539 //=================================================================
540 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
541 const bool updateViewer,
542 SALOME_View* theViewFrame )
544 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
547 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
551 vf->BeforeDisplay( this, prs );
552 vf->Display( this, prs );
553 vf->AfterDisplay( this, prs );
558 delete prs; // delete presentation because displayer is its owner
563 //=================================================================
565 * GEOM_Displayer::Display
566 * This overloaded Display() method can be useful for operations
567 * not using dialog boxes.
569 //=================================================================
570 void GEOM_Displayer::Display( GEOM::GEOM_BaseObject_ptr theObj, const bool updateViewer )
572 if ( theObj->_is_nil() )
575 std::string entry = getEntry( theObj );
577 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
582 //=================================================================
584 * GEOM_Displayer::Erase
585 * Erase interactive object in the current viewer
587 //=================================================================
588 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
590 const bool updateViewer,
591 SALOME_View* theViewFrame )
593 if ( theIO.IsNull() )
596 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
599 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
601 vf->BeforeErase( this, prs );
602 vf->Erase( this, prs, forced );
603 vf->AfterErase( this, prs );
606 delete prs; // delete presentation because displayer is its owner
611 //=================================================================
613 * GEOM_Displayer::Erase
614 * Erase geometry object in the current viewer
616 //=================================================================
617 void GEOM_Displayer::Erase( GEOM::GEOM_BaseObject_ptr theObj,
619 const bool updateViewer,
620 SALOME_View* theViewFrame)
622 std::string entry = getEntry( theObj );
625 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
626 forced, updateViewer, theViewFrame);
630 //=================================================================
632 * GEOM_Displayer::Redisplay
633 * Redisplay (erase and then display again) interactive object
634 * in the current viewer
636 //=================================================================
637 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
638 const bool updateViewer,
639 const bool checkActiveViewer )
641 bool aRedisplayed = myIsRedisplayed;
642 myIsRedisplayed = true;
643 // Remove the object permanently (<forced> == true)
644 SUIT_Session* ses = SUIT_Session::session();
645 SUIT_Application* app = ses->activeApplication();
648 SUIT_Desktop* desk = app->desktop();
649 QList<SUIT_ViewWindow*> wnds = desk->windows();
650 SUIT_ViewWindow* wnd;
651 QListIterator<SUIT_ViewWindow*> it( wnds );
652 while ( it.hasNext() && (wnd = it.next()) )
654 SUIT_ViewManager* vman = wnd->getViewManager();
657 SUIT_ViewModel* vmodel = vman->getViewModel();
660 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
663 if ( view->isVisible( theIO ) || ( checkActiveViewer && view == GetActiveView() ) )
665 Redisplay( theIO, updateViewer, view );
672 myIsRedisplayed = aRedisplayed;
675 //=================================================================
677 * GEOM_Displayer::Redisplay
678 * Redisplay (erase and then display again) interactive object
679 * in the specified view
681 //=================================================================
682 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
683 const bool theUpdateViewer,
684 SALOME_View* theViewFrame )
686 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
692 bool aRedisplayed = myIsRedisplayed;
693 myIsRedisplayed = true;
694 Erase( theIO, true, false, theViewFrame );
695 Display( theIO, theUpdateViewer, theViewFrame );
696 myIsRedisplayed = aRedisplayed;
697 // hide annotations for erased presentation
698 SUIT_Session* session = SUIT_Session::session();
699 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
700 GeometryGUI* aModule = dynamic_cast<GeometryGUI*>( anApp->activeModule() );
702 if ( !theViewFrame->isVisible( theIO ) ) {
703 aModule->GetAnnotationMgr()->EraseVisibleAnnotations(QString(theIO->getEntry()), dynamic_cast<SOCC_Viewer*>( theViewFrame ));
706 aModule->GetAnnotationMgr()->DisplayVisibleAnnotations(QString(theIO->getEntry()), dynamic_cast<SOCC_Viewer*>( theViewFrame ));
711 //=================================================================
713 * GEOM_Displayer::Display
714 * Calls Display() method for each object in the given list
716 //=================================================================
717 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
719 SALOME_ListIteratorOfListIO Iter( theIOList );
720 for ( ; Iter.More(); Iter.Next() ) {
721 Display( Iter.Value(), false );
727 void GEOM_Displayer::UpdateVisibility( SALOME_View* v, const SALOME_Prs* p, bool on )
729 SalomeApp_Study* aStudy = getStudy();
731 if ( v ) vId = getViewManagerId( v );
734 QString entry = p->GetEntry();
735 if ( !entry.isEmpty() ) {
737 aStudy->setObjectProperty( vId, entry, GEOM::propertyName( GEOM::Visibility ), on );
738 setVisibilityState( entry, on ? Qtx::ShownState : Qtx::HiddenState );
743 aStudy->setObjectProperty( vId, GEOM::propertyName( GEOM::Visibility ), on );
748 Quantity_Color GEOM_Displayer::qColorFromResources( const QString& property, const QColor& defColor )
750 // VSR: this method can be improved in future:
751 // to improve performance, the default values from resource manager should be cached in the displayer
752 return SalomeApp_Tools::color( SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor ) );
755 QColor GEOM_Displayer::colorFromResources( const QString& property, const QColor& defColor )
757 // VSR: this method can be improved in future:
758 // to improve performance, the default values from resource manager should be cached in the displayer
759 return SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor );
762 void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShape, bool create )
764 // check that shape is not null
765 if ( AISShape.IsNull() ) return;
767 // check that study is active
768 SalomeApp_Study* study = getStudy();
769 if ( !study ) return;
771 if ( myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
772 !TopoDS_Iterator(myShape).More() )
773 return; // NPAL15983 (Bug when displaying empty groups)
775 // set interactive object
777 Handle( SALOME_InteractiveObject ) anIO;
779 if ( !myIO.IsNull() ) {
780 AISShape->setIO( myIO );
781 AISShape->SetOwner( myIO );
784 else if ( !myName.empty() ) {
785 // workaround to allow selection of temporary objects
786 static int tempId = 0;
787 anIO = new SALOME_InteractiveObject( QString( "TEMP_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
788 AISShape->setIO( anIO );
789 AISShape->SetOwner( anIO );
792 // flag: only vertex or compound of vertices is processed (specific handling)
793 bool onlyVertex = myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape );
794 // presentation study entry (empty for temporary objects like preview)
795 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
796 // flag: temporary object
797 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
798 // currently active view window's ID (-1 if no active view)
799 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
801 // get presentation properties
802 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
804 // Temporary staff: vertex must be infinite for correct visualization
805 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
808 Material_Model material;
809 // if predefined color isn't set in displayer(via GEOM_Displayer::SetColor() function)
811 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
812 // - set front material properties
813 AISShape->SetCurrentFacingModel( Aspect_TOFM_FRONT_SIDE );
814 AISShape->SetMaterial( material.getMaterialOCCAspect( true ) );
815 // - set back material properties
816 AISShape->SetCurrentFacingModel( Aspect_TOFM_BACK_SIDE );
817 AISShape->SetMaterial( material.getMaterialOCCAspect( false ) );
818 // - switch to default (both sides) facing mode
819 AISShape->SetCurrentFacingModel( Aspect_TOFM_BOTH_SIDE );
825 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function;
826 // we set it to the shape not taking into account material properties
827 AISShape->SetShadingColor( (Quantity_NameOfColor)GetColor() );
829 else if ( !material.isPhysical() ) {
830 // shading color from properties is used only for non-physical materials
831 AISShape->SetShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>() ) );
835 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
836 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
837 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
838 AISShape->Attributes()->SetLineAspect( anAspect );
840 // - unfree boundaries color
841 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
842 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
843 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
844 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
846 // - free boundaries color
847 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
848 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
849 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>() ) );
850 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
852 // - standalone edges color
853 anAspect = AISShape->Attributes()->WireAspect();
854 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
855 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>() ) );
856 AISShape->Attributes()->SetWireAspect( anAspect );
858 // - color for edges in shading+edges mode
859 AISShape->SetEdgesInShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
861 // - color of labels (textual fields and shape name)
862 AISShape->SetLabelColor( qColorFromResources( "label_color", QColor( 255, 255, 255 ) ) );
865 int displayMode = HasDisplayMode() ?
866 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
868 // display mode from properties
869 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
870 AISShape->SetDisplayMode( displayMode );
872 // - face boundaries color and line width
873 anAspect = AISShape->Attributes()->FaceBoundaryAspect();
874 anAspect->SetColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
875 anAspect->SetWidth( HasWidth() ? GetWidth() : propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
876 AISShape->Attributes()->SetFaceBoundaryAspect( anAspect );
878 // set display vectors flag
879 AISShape->SetDisplayVectors( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
881 // set display vertices flag
882 bool isVerticesMode = propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool();
883 AISShape->SetDisplayVertices( isVerticesMode );
885 // set display name flag
886 bool isNameMode = propMap.value( GEOM::propertyName( GEOM::ShowName ) ).toBool();
887 AISShape->SetDisplayName( isNameMode );
890 if( HasTransparency() ) {
891 AISShape->SetTransparency( GetTransparency() );
893 AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
896 // set iso properties
897 int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt();
898 int vIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[1].toInt();
899 Quantity_Color isosColor = SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>() );
900 int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt();
901 Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect();
902 Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect();
904 if ( HasIsosColor() ) {
905 uIsoAspect->SetColor( (Quantity_NameOfColor)GetIsosColor() );
906 vIsoAspect->SetColor( (Quantity_NameOfColor)GetIsosColor() );
909 uIsoAspect->SetColor( isosColor );
910 vIsoAspect->SetColor( isosColor );
913 if ( HasIsosWidth() ) {
914 uIsoAspect->SetWidth( GetIsosWidth() );
915 vIsoAspect->SetWidth( GetIsosWidth() );
918 uIsoAspect->SetWidth( isosWidth );
919 vIsoAspect->SetWidth( isosWidth );
923 uIsoAspect->SetNumber( GetNbIsos() );
924 vIsoAspect->SetNumber( GetNbIsos() );
927 uIsoAspect->SetNumber( uIsos );
928 vIsoAspect->SetNumber( vIsos );
931 AISShape->Attributes()->SetUIsoAspect( uIsoAspect );
932 AISShape->Attributes()->SetVIsoAspect( vIsoAspect );
934 // set deflection coefficient
935 // ... to avoid to small values of the coefficient, its lower value is limited
936 AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) );
940 if ( HasTexture() ) {
941 // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function
942 aImagePath = GetTexture().c_str();
943 if ( ! entry.isEmpty() ) {
944 // check that study is active
945 SalomeApp_Study* study = getActiveStudy();
947 // Store the texture in object properties for next displays
948 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) );
949 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
951 // Update propeties map
952 propMap = getObjectProperties( study, entry, myViewFrame );
957 aImagePath = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
960 Handle(Image_PixMap) aPixmap;
961 if ( !aImagePath.isEmpty() )
962 aPixmap = cacheTextureFor( aImagePath, AISShape );
964 aPixmap = getDefaultTexture();
966 // apply image to shape
967 if ( !aPixmap.IsNull() ) {
968 AISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMap( new Graphic3d_Texture2Dmanual( aPixmap ) );
970 if ( displayMode == GEOM_AISShape::TexturedShape )
971 AISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn();
973 AISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOff();
976 AISShape->SetWidth( HasWidth() ?
977 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
979 // libe width from properties
980 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
982 // set top-level flag
983 AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
985 // set point marker (for vertex / compound of vertices only)
986 if ( onlyVertex || isVerticesMode ) {
987 QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
988 if ( aList.size() == 2 ) {
989 // standard marker string contains "TypeOfMarker:ScaleOfMarker"
990 int aTypeOfMarker = aList[0].toInt();
991 double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
992 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
993 anAspect->SetScale( aScaleOfMarker );
994 anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
995 anAspect->SetColor( HasColor() ?
996 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
997 (Quantity_NameOfColor)GetColor() :
998 // color from properties
999 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ) );
1000 AISShape->Attributes()->SetPointAspect( anAspect );
1002 else if ( aList.size() == 1 ) {
1003 // custom marker string contains "IdOfTexture"
1004 int textureId = aList[0].toInt();
1005 Standard_Integer aWidth, aHeight;
1006 Handle(TColStd_HArray1OfByte) aTexture =
1007 GeometryGUI::getTexture( study, textureId, aWidth, aHeight );
1008 if ( !aTexture.IsNull() ) {
1009 Handle(Prs3d_PointAspect) aTextureAspect =
1010 new Prs3d_PointAspect( HasColor() ?
1011 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1012 (Quantity_NameOfColor)GetColor() :
1013 // color from properties
1014 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
1017 AISShape->Attributes()->SetPointAspect( aTextureAspect );
1022 // set field step data
1023 AISShape->setFieldStepInfo( myFieldDataType,
1027 myFieldStepRangeMin,
1028 myFieldStepRangeMax );
1030 if ( create && !isTemporary && aMgrId != -1 ) {
1031 // set properties to the study
1032 study->setObjectProperties( aMgrId, entry, propMap );
1035 // AISShape->SetName(???); ??? necessary to set name ???
1038 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
1040 // check that actor is not null
1041 if ( !actor ) return;
1043 // check that study is active
1044 SalomeApp_Study* study = getStudy();
1045 if ( !study ) return;
1047 // set interactive object
1049 Handle( SALOME_InteractiveObject ) anIO;
1051 if ( !myIO.IsNull() ) {
1052 actor->setIO( myIO );
1055 else if ( !myName.empty() ) {
1056 // workaround to allow selection of temporary objects
1057 static int tempId = 0;
1058 anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
1059 actor->setIO( anIO );
1062 // presentation study entry (empty for temporary objects like preview)
1063 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
1064 // flag: temporary object
1065 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
1066 // currently active view window's ID (-1 if no active view)
1067 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
1069 // get presentation properties
1070 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
1073 /////////////////////////////////////////////////////////////////////////
1074 // VSR: for VTK viewer currently deflection coefficient is hardcoded
1075 // due to performance problem
1076 // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
1077 /////////////////////////////////////////////////////////////////////////
1078 if ( !actor->getTopo().IsSame( myShape ) )
1079 #ifdef LIMIT_DEFLECTION_FOR_VTK
1080 actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
1082 actor->SetShape( myShape, qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ), myType == GEOM_VECTOR );
1086 Material_Model material;
1087 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
1088 std::vector<vtkProperty*> mprops;
1089 mprops.push_back( material.getMaterialVTKProperty( true ) );
1090 mprops.push_back( material.getMaterialVTKProperty( false) );
1091 actor->SetMaterial( mprops );
1093 // set iso-lines properties
1095 // - set number of iso-lines
1096 int nbIsos[2]= { 1, 1 };
1097 if ( HasNbIsos() ) {
1098 nbIsos[0] = GetNbIsos();
1099 nbIsos[1] = GetNbIsos();
1102 QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
1103 nbIsos[0] = isos[0].toInt();
1104 nbIsos[1] = isos[1].toInt();
1106 actor->SetNbIsos( nbIsos );
1108 // - set iso-lines width
1109 actor->SetIsosWidth( HasIsosWidth() ? GetIsosWidth() : propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
1111 // - set iso-lines color
1112 if ( HasIsosColor() )
1113 c = SalomeApp_Tools::color( Quantity_Color((Quantity_NameOfColor)GetIsosColor()) );
1115 c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
1116 actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
1121 // - same color for all sub-actors
1122 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1123 actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1126 // shading color (for non-physical materials)
1127 if ( !material.isPhysical() ) {
1128 c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
1129 actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1130 actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1133 // - standalone edge color
1134 c = propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>();
1135 actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1137 c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
1138 // - shared edges color ???
1139 actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1141 c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
1142 // - free edges color ???
1143 actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
1146 c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
1147 actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
1150 // - color for edges in shading+edges mode
1151 c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
1152 actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
1154 // - color of labels (shape name)
1155 c = colorFromResources( "label_color", QColor( 255, 255, 255 ) );
1156 actor->SetLabelColor( c.redF(), c.greenF(), c.blueF() );
1159 if( HasTransparency() ) {
1160 actor->SetOpacity( 1.0 - GetTransparency() );
1162 actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
1166 actor->SetWidth( HasWidth() ?
1167 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1169 // libe width from properties
1170 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
1172 // set display vectors flag
1173 actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
1175 // set display vertices flag
1176 actor->SetVerticesMode( propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool() );
1178 // set display name flag
1179 actor->SetNameMode( propMap.value( GEOM::propertyName( GEOM::ShowName ) ).toBool() );
1182 int displayMode = HasDisplayMode() ?
1183 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
1185 // display mode from properties
1186 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
1188 // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
1189 // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
1190 // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
1191 // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
1193 if ( displayMode == 2 )
1194 // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
1195 // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
1197 actor->setDisplayMode( displayMode );
1200 actor->PickableOn();
1202 actor->PickableOff();
1204 if ( create && !isTemporary && aMgrId != -1 ) {
1205 // set properties to the study
1206 study->setObjectProperties( aMgrId, entry, propMap );
1210 //=================================================================
1212 * GEOM_Displayer::updateDimensions
1213 * Creates or renews dimension presentation for the IO.
1215 //=================================================================
1216 void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& theIO,
1217 SALOME_OCCPrs* thePrs,
1218 const gp_Ax3& theShapeLCS )
1220 SalomeApp_Study* aStudy = getStudy();
1226 if ( theIO.IsNull() )
1231 SOCC_Prs* anOccPrs = dynamic_cast<SOCC_Prs*>( thePrs );
1233 AIS_ListOfInteractive aListOfIO;
1235 anOccPrs->GetObjects( aListOfIO );
1237 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
1239 // remove outdated presentations of dimensions
1240 for ( ; aIterateIO.More(); aIterateIO.Next() )
1242 const Handle(AIS_InteractiveObject)& anIO = aIterateIO.Value();
1243 if ( !anIO->IsKind( STANDARD_TYPE( AIS_Dimension ) ) )
1248 aListOfIO.Remove( aIterateIO );
1250 if ( !aIterateIO.More() )
1256 // prepare dimension styling
1257 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1259 QColor aQColor = aResMgr->colorValue ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
1260 int aLineWidth = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
1261 QFont aFont = aResMgr->fontValue ( "Geometry", "dimensions_font", QFont("Y14.5M-2009", 14) );
1262 double anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
1263 bool isUnitsShown = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
1264 QString aUnitsLength = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
1265 QString aUnitsAngle = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
1266 bool aUseText3d = aResMgr->booleanValue( "Geometry", "dimensions_use_text3d", false );
1268 // restore dimension presentation from saved attribute or property data
1269 AIS_ListOfInteractive aRestoredDimensions;
1271 QVariant aProperty = aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1273 GEOM::propertyName( GEOM::Dimensions ),
1276 GEOMGUI_DimensionProperty aRecords;
1278 if ( aProperty.isValid() && aProperty.canConvert<GEOMGUI_DimensionProperty>() )
1280 aRecords = aProperty.value<GEOMGUI_DimensionProperty>();
1284 aRecords.LoadFromAttribute( getStudy(), theIO->getEntry() );
1287 // create up-to-date dimension presentations
1288 for ( int aPrsIt = 0; aPrsIt < aRecords.GetNumber(); ++aPrsIt )
1290 if ( !aRecords.IsVisible( aPrsIt ) )
1295 // init dimension by type
1296 Handle(AIS_Dimension) aPrs;
1297 switch( aRecords.GetType( aPrsIt ) )
1299 case GEOMGUI_DimensionProperty::DimensionType_Length :
1301 Handle(GEOM_AISLength) aLength = new GEOM_AISLength( aPrsIt );
1302 aRecords.GetRecord( aPrsIt )->AsLength()->Update( aLength, theShapeLCS );
1307 case GEOMGUI_DimensionProperty::DimensionType_Diameter :
1309 Handle(GEOM_AISDiameter) aDiam = new GEOM_AISDiameter( aPrsIt );
1310 aRecords.GetRecord( aPrsIt )->AsDiameter()->Update( aDiam, theShapeLCS );
1315 case GEOMGUI_DimensionProperty::DimensionType_Angle :
1317 Handle(GEOM_AISAngle) anAng = new GEOM_AISAngle( aPrsIt );
1318 aRecords.GetRecord( aPrsIt )->AsAngle()->Update( anAng, theShapeLCS );
1324 aPrs->SetOwner( theIO );
1326 Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
1328 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
1330 aStyle->SetCommonColor( aColor );
1331 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1332 aStyle->MakeText3d( aUseText3d );
1333 aStyle->MakeTextShaded( Standard_True );
1334 int fsize = aFont.pixelSize() != -1 ? aFont.pixelSize() : aFont.pointSize();
1335 aStyle->SetExtensionSize( fsize * 0.5 );
1336 aStyle->TextAspect()->SetFont( aFont.family().toLatin1().data() );
1337 aStyle->TextAspect()->SetHeight( fsize );
1338 aStyle->ArrowAspect()->SetLength( anArrowLength );
1339 aStyle->LineAspect()->SetWidth( aLineWidth );
1340 aStyle->SetTextHorizontalPosition( aPrs->DimensionAspect()->TextHorizontalPosition() );
1341 aStyle->SetTextVerticalPosition( aPrs->DimensionAspect()->TextVerticalPosition() );
1342 aStyle->SetArrowOrientation( aPrs->DimensionAspect()->ArrowOrientation() );
1343 aPrs->SetDimensionAspect( aStyle );
1344 aPrs->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
1345 aPrs->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
1346 aPrs->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
1348 if ( aPrs->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
1350 // show degree symbol for dimension instead of label "deg"
1351 if ( aUnitsAngle == "deg" )
1353 aPrs->SetSpecialSymbol(0xB0);
1354 aPrs->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
1355 aStyle->MakeUnitsDisplayed(Standard_False);
1359 aPrs->SetDisplaySpecialSymbol(AIS_DSS_No);
1360 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1365 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1368 aListOfIO.Append( aPrs );
1371 // update presentation
1374 for ( aIterateIO.Initialize( aListOfIO ); aIterateIO.More(); aIterateIO.Next() )
1376 anOccPrs->AddObject( aIterateIO.Value() );
1380 //=================================================================
1382 * GEOM_Displayer::Erase
1383 * Calls Erase() method for each object in the given list
1385 //=================================================================
1386 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
1388 const bool updateViewer )
1390 SALOME_ListIteratorOfListIO Iter( theIOList );
1391 for ( ; Iter.More(); Iter.Next() )
1392 Erase( Iter.Value(), forced, false );
1398 //=================================================================
1400 * GEOM_Displayer::Redisplay
1401 * Calls Redisplay() method for each object in the given list
1403 //=================================================================
1404 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1405 const bool updateViewer,
1406 const bool checkActiveViewer )
1408 SALOME_ListIteratorOfListIO Iter( theIOList );
1409 for ( ; Iter.More(); Iter.Next() )
1410 Redisplay( Iter.Value(), false, checkActiveViewer );
1416 //=================================================================
1418 * GEOM_Displayer::Redisplay
1419 * Calls Redisplay() method for each object in the given list
1421 //=================================================================
1422 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1423 const bool theUpdateViewer,
1424 SALOME_View* theViewFrame )
1426 SALOME_ListIteratorOfListIO anIter( theIOList );
1427 for ( ; anIter.More(); anIter.Next() )
1429 Redisplay( anIter.Value(), false, theViewFrame );
1432 if ( theUpdateViewer )
1438 //=================================================================
1440 * GEOM_Displayer::Update
1441 * Update OCC presentaion
1442 * [ Reimplemented from SALOME_Displayer ]
1444 //=================================================================
1445 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
1447 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
1448 SalomeApp_Study* study = getStudy();
1450 if ( !occPrs || myShape.IsNull() || !study )
1453 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1456 // specific processing for local coordinate system presentation
1459 TopoDS_Face aFace = TopoDS::Face( myShape );
1460 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1461 if ( !aPlane.IsNull() )
1463 gp_Ax3 aPos = aPlane->Pln().Position();
1464 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1466 Handle(GEOM_AISTrihedron) aTrh;
1468 if ( occPrs->IsNull() )
1470 // new presentation is being created
1471 aTrh = new GEOM_AISTrihedron( aPlc );
1472 occPrs->AddObject( aTrh );
1476 // presentation is being updated
1477 AIS_ListOfInteractive aList;
1478 occPrs->GetObjects( aList );
1479 AIS_ListIteratorOfListOfInteractive anIter( aList );
1480 for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
1481 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
1485 if ( !aTrh.IsNull() ) {
1486 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1488 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1489 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1491 aTrh->SetWidth( GetWidth() );
1493 if ( !myIO.IsNull() )
1495 aTrh->setIO( myIO );
1496 aTrh->SetOwner( myIO );
1498 aTrh->SetComponent( aPlc );
1499 aTrh->SetToUpdate();
1501 occPrs->SetToActivate( ToActivate() );
1507 // processing for usual geometry presentation
1510 // if presentation is empty we try to create new one
1511 if ( occPrs->IsNull() )
1513 // create presentation (specific for vectors)
1514 Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1515 : new GEOM_AISShape ( myShape, "" );
1517 if( myType == GEOM_FIELD_STEP )
1518 AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight );
1519 // update shape properties
1520 updateShapeProperties( AISShape, true );
1522 // add shape to the presentation
1523 occPrs->AddObject( AISShape );
1525 // In accordance with ToActivate() value object will be activated/deactivated
1526 // when it will be displayed
1527 occPrs->SetToActivate( ToActivate() );
1529 if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1530 // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1532 // create additional wireframe shape
1533 Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1534 aWirePrs->SetWidth(AISShape->Width());
1535 if ( !myIO.IsNull() ) {
1536 aWirePrs->setIO( myIO );
1537 aWirePrs->SetOwner( myIO );
1540 // add shape to the presentation
1541 occPrs->AddObject( aWirePrs );
1544 // if presentation is found -> set again shape for it
1547 AIS_ListOfInteractive IOList;
1548 occPrs->GetObjects( IOList );
1549 AIS_ListIteratorOfListOfInteractive Iter( IOList );
1550 for ( ; Iter.More(); Iter.Next() )
1552 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1553 if ( AISShape.IsNull() )
1556 // re-set shape (it might be changed)
1557 if ( AISShape->Shape() != myShape )
1558 AISShape->Set( myShape );
1560 // update shape properties
1561 updateShapeProperties( AISShape, false );
1564 AISShape->UpdateSelection();
1565 AISShape->SetToUpdate();
1569 updateDimensions( myIO, occPrs, gp_Ax3().Transformed( myShape.Location().Transformation() ) );
1573 //=================================================================
1575 * GEOM_Displayer::Update
1576 * Update VTK presentaion
1577 * [ Reimplemented from SALOME_Displayer ]
1579 //=================================================================
1580 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1582 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1583 SalomeApp_Study* study = getStudy();
1585 if ( !vtkPrs || myShape.IsNull() || !study )
1588 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1591 // specific processing for local coordinate system presentation
1594 TopoDS_Face aFace = TopoDS::Face( myShape );
1595 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1596 if ( !aPlane.IsNull() ) {
1597 gp_Ax3 aPos = aPlane->Pln().Position();
1598 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1600 GEOM_VTKTrihedron* aTrh = 0;
1602 if ( vtkPrs->IsNull() ) {
1603 // new presentation is being created
1604 aTrh = GEOM_VTKTrihedron::New();
1605 vtkPrs->AddObject( aTrh );
1608 // presentation is being updated
1609 vtkActorCollection* actors = vtkPrs->GetObjects();
1611 actors->InitTraversal();
1612 vtkActor* a = actors->GetNextActor();
1613 while ( a && !aTrh ) {
1614 aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1615 a = actors->GetNextActor();
1621 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1623 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1624 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1626 #ifdef VTK_TRIHEDRON_WIDTH
1628 // VSR: currently isn't supported
1630 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1632 aTrh->SetWidth( GetWidth() );
1635 if ( !myIO.IsNull() )
1636 aTrh->setIO( myIO );
1638 aTrh->SetPlacement( aPlc );
1645 // processing for usual geometry presentation
1648 // if presentation is empty we try to create new one
1649 if ( vtkPrs->IsNull() )
1652 GEOM_Actor* actor = GEOM_Actor::New();
1653 // update actor properties
1654 updateActorProperties( actor, true );
1655 // add actor to the presentation
1656 vtkPrs->AddObject( actor );
1659 // presentation is being updated
1660 vtkActorCollection* actors = vtkPrs->GetObjects();
1662 actors->InitTraversal();
1663 vtkActor* a = actors->GetNextActor();
1665 GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1667 // update actor properties
1668 updateActorProperties( actor, false );
1669 a = actors->GetNextActor();
1677 //=================================================================
1679 * GEOM_Displayer::BuildPrs
1680 * Build presentation accordint to the current viewer type
1682 //=================================================================
1683 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1685 if ( theObj->_is_nil() )
1688 myViewFrame = GetActiveView();
1689 if ( myViewFrame == 0 )
1692 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1697 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1698 myType = theObj->GetType();
1700 // Update presentation
1706 //=================================================================
1708 * GEOM_Displayer::BuildPrs
1709 * Build presentation accordint to the current viewer type
1711 //=================================================================
1712 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1714 myViewFrame = GetActiveView();
1715 if ( theShape.IsNull() || myViewFrame == 0 )
1718 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1723 setShape( theShape );
1731 //=================================================================
1733 * GEOM_Displayer::buildPresentation
1734 * Builds/finds object's presentation for the current viewer
1735 * Calls corresponding Update() method by means of double dispatch
1738 //=================================================================
1739 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1740 SALOME_View* theViewFrame )
1742 SALOME_Prs* prs = 0;
1745 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1749 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1752 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1753 theIO->setEntry( entry.toLatin1().constData() );
1754 if ( !theIO.IsNull() )
1756 // set interactive object
1758 // Find SOBject (because shape should be published previously)
1759 SUIT_Session* session = SUIT_Session::session();
1760 SUIT_Application* app = session->activeApplication();
1763 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1766 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1769 // get CORBA reference to data object
1770 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1771 if ( !CORBA::is_nil( object ) )
1773 // downcast to GEOM base object
1774 GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
1775 if ( !GeomBaseObject->_is_nil() )
1777 myType = GeomBaseObject->GetType();
1779 // downcast to GEOM object
1780 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
1781 if ( myType == GEOM_FIELD_STEP )
1783 // get the GEOM object from the field's shape
1784 GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
1785 if ( !GeomFieldStep->_is_nil() )
1787 GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
1788 if ( !GeomField->_is_nil() )
1789 GeomObject = GeomField->GetShape();
1792 // read the field step information
1793 readFieldStepInfo( GeomFieldStep );
1796 if ( !GeomObject->_is_nil() )
1798 theIO->setName( GeomObject->GetName() );
1799 // finally set shape
1800 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1808 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1814 //=================================================================
1816 * GEOM_Displayer::buildSubshapePresentation
1817 * Builds/finds object's presentation for the current viewer
1818 * Calls corresponding Update() method by means of double dispatch
1819 * For not published objects (for Mantis issue 0020435)
1821 //=================================================================
1822 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1823 const QString& entry,
1824 SALOME_View* theViewFrame)
1826 SALOME_Prs* prs = 0;
1829 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1833 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1836 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1837 theIO->setEntry(entry.toLatin1().constData());
1838 if (!theIO.IsNull())
1840 // set interactive object
1842 // finally set shape
1844 myType = GEOM_SUBSHAPE;
1846 UpdatePrs(prs); // Update presentation by using of the double dispatch
1852 //=================================================================
1854 * GEOM_Displayer::internalReset
1855 * Resets internal data
1858 //=================================================================
1859 void GEOM_Displayer::internalReset()
1864 myFieldDataType = GEOM::FDT_Double;
1865 myFieldDimension = 0;
1866 myFieldStepData.clear();
1867 myFieldStepName.Clear();
1868 myFieldStepRangeMin = 0;
1869 myFieldStepRangeMax = 0;
1872 //=================================================================
1874 * GEOM_Displayer::LocalSelection
1875 * Activate selection of CAD shapes with activisation of selection
1876 * of their sub-shapes (with opened local context for OCC viewer)
1878 //=================================================================
1879 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const std::list<int> modes )
1881 SUIT_Session* session = SUIT_Session::session();
1882 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1886 LightApp_SelectionMgr* sm = app->selectionMgr();
1888 // remove all filters from selection
1891 SALOME_View* vf = GetActiveView();
1893 if (!theIO.IsNull() && !vf->isVisible(theIO))
1895 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1896 vf->LocalSelection( prs, modes );
1897 delete prs; // delete presentation because displayer is its owner
1901 //=================================================================
1903 * GEOM_Displayer::LocalSelection
1904 * Activate selection of CAD shapes with activisation of selection
1905 * of their sub-shapes (with opened local context for OCC viewer)
1907 //=================================================================
1908 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1910 std::list<int> modes;
1911 modes.push_back( theMode );
1912 LocalSelection( theIO, modes );
1915 //=================================================================
1917 * GEOM_Displayer::globalSelection
1918 * Activate selection of CAD shapes without activisation of selection
1919 * of their sub-shapes (without opened local context for OCC viewer)
1921 //=================================================================
1922 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1924 TColStd_MapOfInteger aModes;
1925 aModes.Add( theMode );
1926 GlobalSelection( aModes, update );
1929 //=================================================================
1931 * GEOM_Displayer::globalSelection
1932 * Activate selection of CAD shapes without activisation of selection
1933 * of their sub-shapes (without opened local context for OCC viewer)
1935 //=================================================================
1936 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1937 const bool update, const QList<int>* theSubShapes )
1939 SUIT_Session* session = SUIT_Session::session();
1940 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1944 SALOME_View* vf = GetActiveView();
1948 // Close local context
1949 vf->GlobalSelection( update );
1951 // Set selection filters in accordance with current mode
1952 LightApp_SelectionMgr* sm = app->selectionMgr();
1956 // Remove from selection temporary objects if necessary
1957 if ( !theModes.Contains( GEOM_PREVIEW ) )
1958 clearTemporary( sm );
1960 //@ aSel->ClearIndex();
1964 // Remove filters from AIS_InteractiveContext
1965 Handle(AIS_InteractiveContext) ic;
1966 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1969 ic = viewer->getAISContext();
1971 ic->RemoveFilters();
1974 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1977 SUIT_SelectionFilter* aFilter;
1978 if ( theModes.Extent() == 1 )
1980 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1982 if ( aMode == GEOM_COMPOUNDFILTER )
1983 aFilter = getComplexFilter( theSubShapes );
1985 aFilter = getFilter( aMode );
1987 else if ( theModes.Extent() > 1 )
1989 TColStd_MapOfInteger aTopAbsModes;
1990 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1991 QList<SUIT_SelectionFilter*> aListOfFilters;
1992 for ( ; anIter.More(); anIter.Next() )
1994 SUIT_SelectionFilter* aFilter;
1995 int aMode = anIter.Key();
1996 if ( aMode == GEOM_COMPOUNDFILTER )
1997 aFilter = getComplexFilter( theSubShapes );
1999 aFilter = getFilter( aMode );
2002 aListOfFilters.append( aFilter );
2005 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
2012 sm->installFilter( aFilter );
2015 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
2016 ic->AddFilter( anOCCFilter );
2021 //=================================================================
2023 * GEOM_Displayer::LocalSelection
2024 * Activate selection of CAD shapes with activisation of selection
2025 * of their sub-shapes (with opened local context for OCC viewer)
2027 //=================================================================
2028 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const std::list<int> modes )
2030 SALOME_ListIteratorOfListIO Iter( theIOList );
2031 for ( ; Iter.More(); Iter.Next() )
2032 LocalSelection( Iter.Value(), modes );
2035 //=================================================================
2037 * GEOM_Displayer::LocalSelection
2038 * Activate selection of CAD shapes with activisation of selection
2039 * of their sub-shapes (with opened local context for OCC viewer)
2041 //=================================================================
2042 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
2044 std::list<int> modes;
2045 modes.push_back( theMode );
2046 LocalSelection( theIOList, modes );
2049 //=================================================================
2051 * GEOM_Displayer::BeforeDisplay
2052 * Called before displaying of pars. Close local context
2053 * [ Reimplemented from SALOME_Displayer ]
2055 //=================================================================
2056 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
2058 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
2061 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
2064 if ( ic->HasOpenedContext() )
2065 ic->CloseAllContexts(Standard_True);
2070 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
2072 UpdateColorScale(false,false);
2074 // visualize annotations for displayed presentation
2075 SUIT_Session* session = SUIT_Session::session();
2076 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2077 GeometryGUI* aModule = dynamic_cast<GeometryGUI*>( anApp->activeModule() );
2079 if ( !myIsRedisplayed ) {
2080 aModule->GetAnnotationMgr()->DisplayVisibleAnnotations(QString(p->GetEntry()), dynamic_cast<SOCC_Viewer*>( v ));
2082 aModule->GetAnnotationMgr()->UpdateVisibleAnnotations(QString(p->GetEntry()), dynamic_cast<SOCC_Viewer*>( v ));
2087 void GEOM_Displayer::BeforeErase( SALOME_View* v, const SALOME_OCCPrs* p )
2089 LightApp_Displayer::BeforeErase( v, p );
2090 releaseTextures( p );
2093 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
2095 LightApp_Displayer::AfterErase( v, p );
2096 UpdateColorScale(false,false);
2098 if ( !myIsRedisplayed ) {
2099 // hide annotations for erased presentation
2100 SUIT_Session* session = SUIT_Session::session();
2101 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2102 GeometryGUI* aModule = dynamic_cast<GeometryGUI*>( anApp->activeModule() );
2104 aModule->GetAnnotationMgr()->EraseVisibleAnnotations(QString(p->GetEntry()), dynamic_cast<SOCC_Viewer*>( v ));
2108 //=================================================================
2110 * GEOM_Displayer::SetColor
2111 * Set color for shape displaying. If it is equal -1 then default color is used.
2112 * Available values are from Quantity_NameOfColor enumeration
2114 //=================================================================
2115 void GEOM_Displayer::SetColor( const int color )
2122 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
2126 int GEOM_Displayer::GetColor() const
2131 bool GEOM_Displayer::HasColor() const
2133 return myColor != -1;
2136 void GEOM_Displayer::UnsetColor()
2140 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2141 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
2142 myShadingColor = SalomeApp_Tools::color( col );
2145 //=================================================================
2147 * GEOM_Displayer::SetTransparency
2148 * Set transparency for shape displaying.
2150 //=================================================================
2151 double GEOM_Displayer::SetTransparency( const double transparency )
2153 double prevTransparency = myTransparency;
2154 myTransparency = transparency;
2155 return prevTransparency;
2158 //=================================================================
2160 * GEOM_Displayer::GetTransparency
2161 * Get transparency for shape displaying.
2163 //=================================================================
2164 double GEOM_Displayer::GetTransparency() const
2166 return myTransparency;
2169 //=================================================================
2171 * GEOM_Displayer::HasTransparency
2172 * Check if transparency for shape displaying is set.
2174 //=================================================================
2175 bool GEOM_Displayer::HasTransparency() const
2177 return myTransparency >= 0;
2180 //=================================================================
2182 * GEOM_Displayer::UnsetTransparency
2183 * Unset transparency for shape displaying.
2185 //=================================================================
2186 double GEOM_Displayer::UnsetTransparency()
2188 return SetTransparency( -1 );
2191 //=================================================================
2193 * GEOM_Displayer::SetTexture
2195 //=================================================================
2196 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
2198 myTexture = texureFileName;
2201 bool GEOM_Displayer::HasTexture() const
2203 return myTexture != "";
2206 std::string GEOM_Displayer::GetTexture() const
2211 //=================================================================
2213 * GEOM_Displayer::SetWidth
2214 * Set width of shape displaying. If it is equal -1 then default width is used.
2216 //=================================================================
2217 void GEOM_Displayer::SetWidth( const double width )
2222 double GEOM_Displayer::GetWidth() const
2227 bool GEOM_Displayer::HasWidth() const
2229 return myWidth != -1;
2232 void GEOM_Displayer::UnsetWidth()
2237 int GEOM_Displayer::GetIsosWidth() const
2242 void GEOM_Displayer::SetIsosWidth(const int width)
2244 myIsosWidth = width;
2247 bool GEOM_Displayer::HasIsosWidth() const
2249 return myIsosWidth != -1;
2252 int GEOM_Displayer::SetNbIsos( const int nbIsos )
2254 int prevNbIsos = myNbIsos;
2259 int GEOM_Displayer::UnsetNbIsos()
2261 return SetNbIsos( -1 );
2264 int GEOM_Displayer::GetNbIsos() const
2269 bool GEOM_Displayer::HasNbIsos() const
2271 return myNbIsos >= 0;
2274 int GEOM_Displayer::SetIsosColor( const int color )
2276 int prevColor = myIsosColor;
2277 myIsosColor = color;
2281 int GEOM_Displayer::GetIsosColor() const
2286 bool GEOM_Displayer::HasIsosColor() const
2288 return myIsosColor != -1;
2291 int GEOM_Displayer::UnsetIsosColor()
2293 return SetIsosColor( -1 );
2296 //=================================================================
2298 * GEOM_Displayer::SetToActivate
2299 * This method is used for activisation/deactivisation of objects to be displayed
2301 //=================================================================
2302 void GEOM_Displayer::SetToActivate( const bool toActivate )
2304 myToActivate = toActivate;
2306 bool GEOM_Displayer::ToActivate() const
2308 return myToActivate;
2311 //=================================================================
2313 * GEOM_Displayer::clearTemporary
2314 * Removes from selection temporary objects
2316 //=================================================================
2317 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
2319 SALOME_ListIO selected, toSelect;
2320 theSelMgr->selectedObjects( selected );
2322 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
2323 Handle(SALOME_InteractiveObject) io = it.Value();
2324 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
2325 toSelect.Append( it.Value() );
2328 theSelMgr->setSelectedObjects( toSelect, true );
2331 void GEOM_Displayer::SetName( const char* theName )
2336 void GEOM_Displayer::UnsetName()
2341 SalomeApp_Study* GEOM_Displayer::getStudy() const
2343 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2346 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
2351 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
2356 void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
2357 const int theFieldDimension,
2358 const QList<QVariant>& theFieldStepData,
2359 const TCollection_AsciiString& theFieldStepName,
2360 const double theFieldStepRangeMin,
2361 const double theFieldStepRangeMax )
2363 myFieldDataType = theFieldDataType;
2364 myFieldDimension = theFieldDimension;
2365 myFieldStepData = theFieldStepData;
2366 myFieldStepName = theFieldStepName;
2367 myFieldStepRangeMin = theFieldStepRangeMin;
2368 myFieldStepRangeMax = theFieldStepRangeMax;
2371 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
2373 _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
2374 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
2375 GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
2376 GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
2377 return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
2378 (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
2381 int GEOM_Displayer::SetDisplayMode( const int theMode )
2383 int aPrevMode = myDisplayMode;
2384 if ( theMode != -1 ) {
2385 myDisplayMode = theMode;
2386 myHasDisplayMode = true;
2394 int GEOM_Displayer::GetDisplayMode() const
2396 return myDisplayMode;
2399 int GEOM_Displayer::UnsetDisplayMode()
2401 int aPrevMode = myDisplayMode;
2402 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2403 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
2404 myHasDisplayMode = false;
2408 bool GEOM_Displayer::HasDisplayMode() const
2410 return myHasDisplayMode;
2413 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
2415 static QList<QColor> colors;
2417 if ( colors.isEmpty() ) {
2419 for (int s = 0; s < 2 ; s++)
2421 for (int v = 100; v >= 40; v = v - 20)
2423 for (int h = 0; h < 359 ; h = h + 60)
2425 colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
2431 static int currentColor = randomize( colors.size() );
2433 SALOMEDS::Color color;
2434 color.R = (double)colors[currentColor].red() / 255.0;
2435 color.G = (double)colors[currentColor].green() / 255.0;
2436 color.B = (double)colors[currentColor].blue() / 255.0;
2438 currentColor = (currentColor+1) % colors.count();
2443 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
2446 int aTolerance = 64;
2447 int anIterations = 0;
2453 if( anIterations % aPeriod == 0 )
2456 if( aTolerance < 1 )
2459 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
2461 aHue = (int)( 360.0 * rand() / RAND_MAX );
2462 //std::cout << "Hue = " << aHue << std::endl;
2464 //std::cout << "Auto colors : ";
2466 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
2467 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
2468 for( ; it != itEnd; ++it )
2470 SALOMEDS::Color anAutoColor = *it;
2471 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
2474 aQColor.getHsv( &h, &s, &v );
2475 //std::cout << h << " ";
2476 if( abs( h - aHue ) < aTolerance )
2479 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
2483 //std::cout << std::endl;
2489 //std::cout << "Hue of the returned color = " << aHue << std::endl;
2491 aColor.setHsv( aHue, 255, 255 );
2493 SALOMEDS::Color aSColor;
2494 aSColor.R = (double)aColor.red() / 255.0;
2495 aSColor.G = (double)aColor.green() / 255.0;
2496 aSColor.B = (double)aColor.blue() / 255.0;
2501 PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
2502 const QString& entry,
2505 // get default properties for the explicitly specified default view type
2506 PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
2508 if ( study && view ) {
2509 SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
2510 SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
2511 int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
2513 if ( viewModel && viewId != -1 ) {
2514 // get properties from the study
2515 PropMap storedMap = study->getObjectProperties( viewId, entry );
2516 // overwrite default properties from stored ones (that are specified)
2517 for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
2518 if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
2519 propMap.insert( GEOM::propertyName( (GEOM::Property)prop ),
2520 storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
2522 // ... specific processing for color
2523 // ... current implementation is to use same stored color for all aspects
2524 // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2525 if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2526 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2527 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2528 propMap.insert( GEOM::propertyName( GEOM::LineColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2529 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2530 propMap.insert( GEOM::propertyName( GEOM::PointColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2533 if ( !entry.isEmpty() ) {
2534 // get CORBA reference to geom object
2535 _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
2537 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
2538 if ( !CORBA::is_nil( object ) ) {
2539 GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
2540 if ( !CORBA::is_nil( geomObject ) ) { // to check
2541 // check that geom object has color properly set
2542 bool hasColor = false;
2543 SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
2544 // set color from geometry object (only once, if it is not yet set in GUI)
2545 // current implementation is to use same color for all aspects
2546 // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2547 if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2548 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
2549 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), objColor );
2550 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
2551 propMap.insert( GEOM::propertyName( GEOM::LineColor ), objColor );
2552 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), objColor );
2553 propMap.insert( GEOM::propertyName( GEOM::PointColor ), objColor );
2555 // check that object has point marker properly set
2556 GEOM::marker_type mType = geomObject->GetMarkerType();
2557 GEOM::marker_size mSize = geomObject->GetMarkerSize();
2558 int mTextureId = geomObject->GetMarkerTexture();
2559 bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) ||
2560 ( mType == GEOM::MT_USER && mTextureId > 0 );
2561 // set point marker from geometry object (only once, if it is not yet set in GUI)
2562 if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
2563 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
2565 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2566 QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
2568 else if ( mType == GEOM::MT_USER ) {
2570 propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
2582 PropMap GEOM_Displayer::getDefaultPropertyMap()
2586 // get resource manager
2587 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2589 // fill in the properties map with default values
2591 // - visibility (false by default)
2592 propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
2594 // - nb isos (take default value from preferences)
2595 propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
2596 QString( "%1%2%3" ).
2597 arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
2598 arg( GEOM::subSectionSeparator() ).
2599 arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
2601 // - transparency (opacity = 1-transparency)
2602 propMap.insert( GEOM::propertyName( GEOM::Transparency ),
2603 resMgr->integerValue( "Geometry", "transparency", 0 ) / 100. );
2605 // - display mode (take default value from preferences)
2606 propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
2607 resMgr->integerValue( "Geometry", "display_mode", 0 ) );
2609 // - show edges direction flag (false by default)
2610 propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
2612 // - show vertices flag (false by default)
2613 propMap.insert( GEOM::propertyName( GEOM::Vertices ), false );
2615 // - show name flag (false by default)
2616 propMap.insert( GEOM::propertyName( GEOM::ShowName ), false );
2618 // - shading color (take default value from preferences)
2619 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
2620 colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
2622 // - wireframe color (take default value from preferences)
2623 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
2624 colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
2626 // - standalone edges color (take default value from preferences)
2627 propMap.insert( GEOM::propertyName( GEOM::LineColor ),
2628 colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
2630 // - free boundaries color (take default value from preferences)
2631 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
2632 colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
2634 // - points color (take default value from preferences)
2635 propMap.insert( GEOM::propertyName( GEOM::PointColor ),
2636 colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
2638 // - isos color (take default value from preferences)
2639 propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
2640 colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
2642 // - outlines color (take default value from preferences)
2643 propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
2644 colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
2646 // - deflection coefficient (take default value from preferences)
2647 propMap.insert( GEOM::propertyName( GEOM::Deflection ),
2648 resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
2650 // - material (take default value from preferences)
2651 Material_Model material;
2652 material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
2653 propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
2655 // - edge width (take default value from preferences)
2656 propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
2657 resMgr->integerValue( "Geometry", "edge_width", 1 ) );
2659 // - isos width (take default value from preferences)
2660 propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
2661 resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
2663 // - point marker (take default value from preferences)
2664 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2665 QString( "%1%2%3" ).
2666 arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
2667 arg( GEOM::subSectionSeparator() ).
2668 arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2670 // - top-level flag (false by default)
2671 propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2676 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2677 SALOMEDS::Color aSColor;
2680 SUIT_Session* session = SUIT_Session::session();
2681 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2683 if ( app && !theGeomObject->_is_nil()) {
2684 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2687 _PTR(Study) aStudy = study->studyDS();
2688 aSColor = theGeomObject->GetColor();
2689 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2691 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2692 bool general_autocolor = true;
2693 #else // auto-color for groups only
2694 bool general_autocolor = false;
2695 #endif // GENERAL_AUTOCOLOR
2696 if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2697 GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2698 if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2699 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2700 aSColor = getPredefinedUniqueColor();
2702 #else // old algorithm for auto-colors
2703 QList<SALOMEDS::Color> aReservedColors;
2704 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2705 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2706 if ( aMainSObject ) {
2707 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2708 for ( ; it->More(); it->Next() ) {
2709 _PTR(SObject) aChildSObject( it->Value() );
2710 GEOM::GEOM_Object_var aChildObject =
2711 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2712 if ( CORBA::is_nil( aChildObject ) )
2715 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2716 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2717 aReservedColors.append( aReservedColor );
2720 aSColor = getUniqueColor( aReservedColors );
2722 #endif // SIMPLE_AUTOCOLOR
2732 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2733 const bool eraseOnlyChildren) {
2734 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2738 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2742 LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2747 // Erase from all views
2748 QList<SALOME_View*> views;
2750 ViewManagerList vmans = app->viewManagers();
2751 SUIT_ViewManager* vman;
2752 foreach ( vman, vmans ) {
2753 SUIT_ViewModel* vmod = vman->getViewModel();
2754 view = dynamic_cast<SALOME_View*> ( vmod );
2756 views.append( view );
2759 if( views.count() == 0 )
2762 //Erase childrens w/o update views
2763 DataObjectList listObj = parent->children( true );
2764 SUIT_DataObject* obj;
2765 foreach( obj, listObj ) {
2766 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2768 foreach ( view, views ) {
2769 Handle(SALOME_InteractiveObject) anIO =
2770 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2771 Erase(anIO, false, false, view);
2775 //Erase parent with view update or repaint views
2776 foreach ( view, views ) {
2777 if(!eraseOnlyChildren)
2778 Erase(theIO, false, true, view);
2784 void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
2786 if( theGeomFieldStep->_is_nil() )
2789 GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
2790 if( aGeomField->_is_nil() )
2793 GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
2794 if( aGeomFieldShape->_is_nil() )
2797 TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
2798 TCollection_AsciiString aFieldName( aGeomField->GetName() );
2799 TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
2801 aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
2803 GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
2805 int aFieldDimension = aGeomField->GetDimension();
2807 GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
2808 int aFieldNbComponents = aFieldComponents->length();
2810 QList<QVariant> aFieldStepData;
2811 if( aFieldDataType == GEOM::FDT_Bool )
2813 GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
2814 if ( !aGeomBoolFieldStep->_is_nil() )
2816 GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
2817 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2818 aFieldStepData << (bool)aValues[i];
2821 else if( aFieldDataType == GEOM::FDT_Int )
2823 GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
2824 if ( !aGeomIntFieldStep->_is_nil() )
2826 GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
2827 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2828 aFieldStepData << (qlonglong)aValues[i];
2831 else if( aFieldDataType == GEOM::FDT_Double )
2833 GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
2834 if ( !aGeomDoubleFieldStep->_is_nil() )
2836 GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
2837 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2838 aFieldStepData << (double)aValues[i];
2841 else if( aFieldDataType == GEOM::FDT_String )
2843 GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
2844 if ( !aGeomStringFieldStep->_is_nil() )
2846 GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
2847 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2848 aFieldStepData << QString( aValues[i] );
2852 double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
2853 aFieldStepData = groupFieldData( aFieldStepData,
2855 aFieldDataType == GEOM::FDT_String,
2857 aFieldStepRangeMax );
2859 setFieldStepInfo( aFieldDataType,
2864 aFieldStepRangeMax );
2867 QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
2868 const int theFieldNbComponents,
2869 const bool theIsString,
2870 double& theFieldStepRangeMin,
2871 double& theFieldStepRangeMax )
2873 QList<QVariant> aResultList;
2874 theFieldStepRangeMin = 0;
2875 theFieldStepRangeMax = 0;
2877 if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
2880 int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
2882 QList<QVariant> aGroupedList;
2884 bool anIsBoolean = false;
2885 for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
2888 QStringList aStringList;
2890 int aBaseIndex = aSubShape * theFieldNbComponents;
2891 for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
2893 int anIndex = aComponent + aBaseIndex;
2895 const QVariant& aVariant = theFieldStepData[ anIndex ];
2898 if( aVariant.type() == QVariant::String )
2899 aStringList << aVariant.toString();
2904 if( aVariant.type() == QVariant::Bool )
2906 aValue = aVariant.toBool() ? 1.0 : 0.0;
2912 if( aVariant.type() == QVariant::LongLong )
2913 aValue = double( aVariant.toLongLong() );
2914 else if( aVariant.type() == QVariant::Double )
2915 aValue = aVariant.toDouble();
2916 aNorm += aValue * aValue;
2922 aGroupedList << aStringList.join( "\n" );
2926 aNorm /= theFieldNbComponents;
2928 aNorm = pow( aNorm, 0.5 );
2930 if( aGroupedList.isEmpty() )
2931 theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
2934 theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
2935 theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
2938 aGroupedList << aNorm;
2944 theFieldStepRangeMin = 0.0;
2945 theFieldStepRangeMax = 1.0;
2948 SUIT_Session* session = SUIT_Session::session();
2949 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2950 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2952 QListIterator<QVariant> anIter( aGroupedList );
2953 while( anIter.hasNext() )
2955 const QVariant& aVariant = anIter.next();
2957 aResultList << aVariant;
2961 Quantity_Color aColor;
2962 if( AIS_ColorScale::FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2963 aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
2964 aResultList << aQColor;
2970 void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, const bool updateViewer )
2972 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2976 SOCC_Viewer* aViewModel = dynamic_cast<SOCC_Viewer*>( GetActiveView() );
2980 Handle(V3d_Viewer) aViewer = aViewModel->getViewer3d();
2981 if( aViewer.IsNull() )
2984 aViewer->InitActiveViews();
2985 if( !aViewer->MoreActiveViews() )
2988 Handle(V3d_View) aView = aViewer->ActiveView();
2989 if( aView.IsNull() )
2992 Standard_Boolean anIsDisplayColorScale = Standard_False;
2993 TCollection_AsciiString aColorScaleTitle;
2994 Standard_Real aColorScaleMin = 0, aColorScaleMax = 0;
2995 Standard_Boolean anIsBoolean = Standard_False;
2997 Handle(SALOME_InteractiveObject) anIO;
2998 if ( myUpdateColorScale )
2999 anIO = myApp->selectionMgr()->soleSelectedObject();
3001 if( !anIO.IsNull() )
3003 SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( aViewModel->CreatePrs( anIO->getEntry() ) );
3006 AIS_ListOfInteractive aList;
3007 aPrs->GetObjects( aList );
3008 AIS_ListIteratorOfListOfInteractive anIter( aList );
3009 for( ; anIter.More(); anIter.Next() )
3011 Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() );
3012 if( !aShape.IsNull() )
3014 GEOM::field_data_type aFieldDataType;
3015 int aFieldDimension;
3016 QList<QVariant> aFieldStepData;
3017 TCollection_AsciiString aFieldStepName;
3018 double aFieldStepRangeMin, aFieldStepRangeMax;
3019 aShape->getFieldStepInfo( aFieldDataType,
3024 aFieldStepRangeMax );
3025 if( !aFieldStepData.isEmpty() && aFieldDataType != GEOM::FDT_String )
3027 anIsDisplayColorScale = Standard_True;
3028 aColorScaleTitle = aFieldStepName;
3029 aColorScaleMin = aFieldStepRangeMin;
3030 aColorScaleMax = aFieldStepRangeMax;
3031 anIsBoolean = aFieldDataType == GEOM::FDT_Bool;
3038 if( anIsDisplayColorScale )
3040 SUIT_Session* session = SUIT_Session::session();
3041 SUIT_ResourceMgr* resMgr = session->resourceMgr();
3043 Standard_Real anXPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
3044 Standard_Real anYPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
3045 Standard_Real aWidth = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
3046 Standard_Real aHeight = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
3047 Standard_Integer aTextHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
3048 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
3050 Standard_Integer aWinWidth = 0, aWinHeight = 0;
3051 aView->Window()->Size (aWinWidth, aWinHeight);
3053 myColorScale->SetPosition (aWinWidth*anXPos, aWinHeight*anYPos);
3054 //myColorScale->SetBreadth (aWinWidth); // ???
3055 myColorScale->SetBreadth (aWinWidth*aWidth); // ???
3056 myColorScale->SetHeight (aWinHeight*aHeight);
3058 myColorScale->SetRange( aColorScaleMin, aColorScaleMax );
3059 myColorScale->SetNumberOfIntervals( anIsBoolean ? 2 : aNbIntervals );
3061 myColorScale->SetTextHeight( aTextHeight );
3062 myColorScale->SetTitle( aColorScaleTitle );
3064 if( !aViewModel->getAISContext()->IsDisplayed( myColorScale ) )
3065 aViewModel->getAISContext()->Display( myColorScale, Standard_True);
3068 if( aViewModel->getAISContext()->IsDisplayed( myColorScale ) )
3069 aViewModel->getAISContext()->Erase( myColorScale, Standard_True );
3072 if( theIsRedisplayFieldSteps )
3074 _PTR(Study) aStudyDS = aStudy->studyDS();
3075 QList<SUIT_ViewManager*> vmList;
3076 myApp->viewManagers( vmList );
3077 for( QList<SUIT_ViewManager*>::Iterator vmIt = vmList.begin(); vmIt != vmList.end(); vmIt++ )
3079 if( SUIT_ViewManager* aViewManager = *vmIt )
3081 const ObjMap& anObjects = aStudy->getObjectProperties( aViewManager->getGlobalId() );
3082 for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ )
3084 _PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) );
3087 CORBA::Object_var anObject = GeometryGUI::ClientSObjectToObject( aSObj );
3088 if( !CORBA::is_nil( anObject ) )
3090 GEOM::GEOM_FieldStep_var aFieldStep = GEOM::GEOM_FieldStep::_narrow( anObject );
3091 if( !aFieldStep->_is_nil() )
3093 CORBA::String_var aStepEntry = aFieldStep->GetStudyEntry();
3094 Handle(SALOME_InteractiveObject) aStepIO =
3095 new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" );
3096 Redisplay( aStepIO, false, false );