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 <Basics_OCCTVersion.hxx>
64 #include <SalomeApp_Study.h>
65 #include <SalomeApp_Application.h>
66 #include <LightApp_SelectionMgr.h>
67 #include <LightApp_DataObject.h>
68 #include <SalomeApp_TypeFilter.h>
69 #include <SalomeApp_Tools.h>
70 #include "utilities.h"
72 #include <SALOME_ListIO.hxx>
73 #include <SALOME_Prs.h>
74 #include "utilities.h"
77 #include <SOCC_ViewModel.h>
80 #include <SVTK_ViewModel.h>
82 #include <OCCViewer_ViewWindow.h>
83 #include <OCCViewer_ViewPort3d.h>
84 #include <OCCViewer_Utilities.h>
87 #include <AIS_Dimension.hxx>
88 #include <AIS_LengthDimension.hxx>
89 #include <AIS_DiameterDimension.hxx>
90 #include <AIS_AngleDimension.hxx>
91 #include <AIS_ListIteratorOfListOfInteractive.hxx>
92 #include <Aspect_PolygonOffsetMode.hxx>
93 #if OCC_VERSION_MAJOR < 7
94 #include <Aspect_ColorScale.hxx>
96 #include <Prs3d_IsoAspect.hxx>
97 #include <Prs3d_PointAspect.hxx>
98 #include <StdSelect_TypeOfEdge.hxx>
99 #include <StdSelect_TypeOfFace.hxx>
100 #include <StdSelect_DisplayMode.hxx>
101 #include <TopoDS_Face.hxx>
102 #include <BRep_Tool.hxx>
103 #include <Geom_Plane.hxx>
104 #include <Geom_Axis2Placement.hxx>
105 #include <Graphic3d_AspectFillArea3d.hxx>
106 #include <gp_Pln.hxx>
107 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
108 #include <TopoDS_Iterator.hxx>
109 #include <Graphic3d_AspectMarker3d.hxx>
110 #include <TopTools_MapOfShape.hxx>
111 #include <TopTools_ListOfShape.hxx>
112 #include <TopTools_ListIteratorOfListOfShape.hxx>
113 #include <TopoDS.hxx>
114 #include <NCollection_DataMap.hxx>
115 #include <NCollection_Map.hxx>
117 #include <Prs3d_ShadingAspect.hxx>
119 #include <BRepMesh_IncrementalMesh.hxx>
122 #include <vtkActorCollection.h>
123 #include <vtkProperty.h>
126 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
128 #include <GEOMImpl_Types.hxx>
130 #include <TColStd_HArray1OfByte.hxx>
132 // If the next macro is defined, autocolor feature works for all sub-shapes;
133 // if it is undefined, autocolor feature works for groups only
134 #define GENERAL_AUTOCOLOR
135 // Below macro, when uncommented, switches on simplified (more performant) algorithm
136 // of auto-color picking up
137 #define SIMPLE_AUTOCOLOR
139 // Hard-coded value of shape deflection coefficient for VTK viewer
140 const double VTK_MIN_DEFLECTION = 0.001;
141 // If the next macro is defined, the deflection coefficient for VTK presentation
142 // is limited by VTK_MIN_DEFLECTION
143 //#define LIMIT_DEFLECTION_FOR_VTK
145 // Pixmap caching support
148 typedef NCollection_Map<Handle(GEOM_AISShape)> SetOfAISShapes;
149 typedef NCollection_DataMap<Handle(Image_PixMap), SetOfAISShapes> PixmapUsageMap;
150 typedef QMap<QString, Handle(Image_PixMap)> PixmapCacheMap;
152 static inline PixmapUsageMap& getPixmapUsageMap()
154 static PixmapUsageMap aMap;
158 static inline PixmapCacheMap& getPixmapCacheMap()
160 static PixmapCacheMap aMap;
164 //===========================================================================
165 // Function : getDefaultTexture
166 // Purpose : Get default texture
167 //===========================================================================
168 static inline Handle(Image_PixMap) getDefaultTexture()
170 static Handle(Image_PixMap) aPixmap;
171 if ( aPixmap.IsNull() ) {
172 QPixmap px(":images/default_texture.png");
174 aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage() );
179 //===========================================================================
180 // Function : cacheTextureFor
181 // Purpose : Load and cache image for the specified presentation.
182 //===========================================================================
183 static inline Handle(Image_PixMap) cacheTextureFor( const QString& thePath,
184 const Handle(GEOM_AISShape)& theShape )
186 if ( thePath.isEmpty() )
189 PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
190 PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
192 Handle(Image_PixMap) aPixmap = aPixmapCacheMap.value( thePath, NULL );
193 if ( !aPixmap.IsNull() ) {
194 // point that the texture is used by the presentation
195 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
196 aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
198 aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
203 // convert texture to compatible image format
204 QImage anImage = QImage( thePath ).convertToFormat( QImage::Format_ARGB32 );
205 if ( anImage.isNull() )
208 aPixmap = OCCViewer_Utilities::imageToPixmap( anImage );
210 aPixmapCacheMap.insert( thePath, aPixmap );
212 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
213 aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
215 aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
220 //===========================================================================
221 // Function : releaseTextures
222 // Purpose : Releases cached textures found for the specified presentation.
223 //===========================================================================
224 static inline void releaseTextures( const SALOME_OCCPrs* thePrs )
226 const SOCC_Prs* anOccPrs = dynamic_cast<const SOCC_Prs*>( thePrs );
228 AIS_ListOfInteractive aListOfIO;
230 anOccPrs->GetObjects( aListOfIO );
232 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
234 PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
235 PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
237 for ( ; aIterateIO.More(); aIterateIO.Next() )
239 Handle(GEOM_AISShape) aAISShape =
240 Handle(GEOM_AISShape)::DownCast( aIterateIO.Value() );
242 if ( aAISShape.IsNull() )
245 #ifdef USE_TEXTURED_SHAPE
246 const Handle(Image_PixMap)& aPixmap = aAISShape->TexturePixMap();
247 if ( aPixmap.IsNull() )
250 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
253 SetOfAISShapes& aUsersShapes = aPixmapUsersMap.ChangeFind( aPixmap );
255 aUsersShapes.Remove( aAISShape );
257 if ( aUsersShapes.IsEmpty() ) {
258 aPixmapUsersMap.UnBind( aPixmap );
259 aPixmapCacheMap.remove( aPixmapCacheMap.key( aPixmap ) );
265 uint randomize( uint size )
267 static bool initialized = false;
268 if ( !initialized ) {
269 qsrand( QDateTime::currentDateTime().toTime_t() );
273 v = uint( (double)( v ) / RAND_MAX * size );
274 v = qMax( uint(0), qMin ( v, size-1 ) );
279 //================================================================
280 // Function : getActiveStudy
281 // Purpose : Get active study, returns 0 if no open study frame
282 //================================================================
283 static inline SalomeApp_Study* getActiveStudy()
285 SUIT_Session* session = SUIT_Session::session();
286 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
288 return ( SalomeApp_Study* )app->activeStudy();
292 static inline int getViewManagerId( SALOME_View* theViewFrame) {
293 SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
294 SUIT_ViewManager* aViewMgr = 0;
296 aViewMgr = aModel->getViewManager();
297 return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
300 //================================================================
301 // Function : getTopAbsMode
302 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
303 // one from GEOMImpl_Types.h
304 //================================================================
305 static inline int getTopAbsMode( const int implType )
309 case GEOM_COMPOUND : return TopAbs_COMPOUND;
310 case GEOM_SOLID : return TopAbs_SOLID;
311 case GEOM_SHELL : return TopAbs_SHELL;
312 case GEOM_FACE : return TopAbs_FACE;
313 case GEOM_WIRE : return TopAbs_WIRE;
314 case GEOM_EDGE : return TopAbs_EDGE;
315 case GEOM_POINT : return TopAbs_VERTEX;
320 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
322 if ( shape.IsNull() )
325 int ret = shape.ShapeType();
327 if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
328 TopoDS_Iterator it(shape, Standard_True, Standard_False);
329 for (; it.More(); it.Next()) {
330 TopoDS_Shape sub_shape = it.Value();
331 if ( sub_shape.IsNull() ) continue;
332 int stype = getMinMaxShapeType( sub_shape, ismin );
333 if ( stype == TopAbs_SHAPE ) continue;
334 if ( ismin && stype > ret )
336 else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
344 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
346 return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
349 //================================================================
350 // Function : getFilter
351 // Purpose : Get filter corresponding to the type of object
352 // from GEOMImpl_Types.h
353 //================================================================
354 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
356 SUIT_SelectionFilter* aFilter;
358 int aTopAbsMode = getTopAbsMode( theMode );
359 if ( aTopAbsMode != -1 )
360 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
364 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
365 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
367 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
368 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
369 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
370 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
371 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
372 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
374 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
376 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
377 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
379 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
385 //================================================================
386 // Function : getComplexFilter
387 // Purpose : Get compound filter corresponding to the type of
388 // object from GEOMImpl_Types.h
389 //================================================================
390 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
392 GEOM_CompoundFilter* aFilter;
394 if(aSubShapes != NULL ) {
395 aFilter = new GEOM_CompoundFilter(getStudy());
396 QList<int> aTopAbsTypes;
397 QList<int>::const_iterator it;
398 for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
399 int topAbsMode = getTopAbsMode(*it);
400 if(topAbsMode != -1 )
401 aTopAbsTypes.append(topAbsMode);
403 aFilter->addSubTypes(aTopAbsTypes);
409 //================================================================
410 // Function : getEntry
412 //================================================================
413 static std::string getEntry( GEOM::GEOM_BaseObject_ptr object )
415 SUIT_Session* session = SUIT_Session::session();
416 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
419 CORBA::String_var IOR = app->orb()->object_to_string( object );
420 if ( strcmp(IOR.in(), "") != 0 )
422 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
423 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
431 //================================================================
432 // Function : getName
434 //================================================================
435 static std::string getName( GEOM::GEOM_BaseObject_ptr object )
437 SUIT_Session* session = SUIT_Session::session();
438 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
441 CORBA::String_var IOR = app->orb()->object_to_string( object );
442 if ( strcmp(IOR.in(), "") != 0 )
444 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
445 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
447 _PTR(GenericAttribute) anAttr;
449 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
451 _PTR(AttributeName) aNameAttr( anAttr );
452 return aNameAttr->Value();
460 //=================================================================
462 * GEOM_Displayer::GEOM_Displayer
465 //=================================================================
466 GEOM_Displayer::GEOM_Displayer()
467 : myUpdateColorScale(true), myIsRedisplayed( false )
469 SUIT_Session* session = SUIT_Session::session();
470 myApp = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
473 SUIT_ResourceMgr* resMgr = session->resourceMgr();
475 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
476 myShadingColor = SalomeApp_Tools::color( col );
478 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
479 myHasDisplayMode = false;
481 int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
483 myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
484 myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
485 myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
487 // Next properties provide a way to customize displaying of presentations;
488 // for instance, this is useful for preview
498 // This parameter is used for activisation/deactivisation (selection) of objects to be displayed
501 // Activate parallel vizualisation by default.
502 // It can be switched OFF via the environment variable:
503 // export PARALLEL_VISU=0
504 Standard_Boolean parallel_visu = Standard_True;
505 char* parallel_visu_env = getenv("PARALLEL_VISU");
506 if (parallel_visu_env && atoi(parallel_visu_env) == 0)
507 parallel_visu = Standard_False;
508 BRepMesh_IncrementalMesh::SetParallelDefault(parallel_visu);
512 #if OCC_VERSION_MAJOR >= 7
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)));
519 myFieldDataType = GEOM::FDT_Double;
520 myFieldDimension = 0;
521 myFieldStepRangeMin = 0;
522 myFieldStepRangeMax = 0;
525 //=================================================================
527 * GEOM_Displayer::~GEOM_Displayer
530 //=================================================================
531 GEOM_Displayer::~GEOM_Displayer()
535 //=================================================================
537 * GEOM_Displayer::Display
538 * Display interactive object in the current viewer
540 //=================================================================
541 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
542 const bool updateViewer,
543 SALOME_View* theViewFrame )
545 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
548 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
552 vf->BeforeDisplay( this, prs );
553 vf->Display( this, prs );
554 vf->AfterDisplay( this, prs );
559 delete prs; // delete presentation because displayer is its owner
564 //=================================================================
566 * GEOM_Displayer::Display
567 * This overloaded Display() method can be useful for operations
568 * not using dialog boxes.
570 //=================================================================
571 void GEOM_Displayer::Display( GEOM::GEOM_BaseObject_ptr theObj, const bool updateViewer )
573 if ( theObj->_is_nil() )
576 std::string entry = getEntry( theObj );
578 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
583 //=================================================================
585 * GEOM_Displayer::Erase
586 * Erase interactive object in the current viewer
588 //=================================================================
589 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
591 const bool updateViewer,
592 SALOME_View* theViewFrame )
594 if ( theIO.IsNull() )
597 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
600 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
602 vf->BeforeErase( this, prs );
603 vf->Erase( this, prs, forced );
604 vf->AfterErase( this, prs );
607 delete prs; // delete presentation because displayer is its owner
612 //=================================================================
614 * GEOM_Displayer::Erase
615 * Erase geometry object in the current viewer
617 //=================================================================
618 void GEOM_Displayer::Erase( GEOM::GEOM_BaseObject_ptr theObj,
620 const bool updateViewer,
621 SALOME_View* theViewFrame)
623 std::string entry = getEntry( theObj );
626 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
627 forced, updateViewer, theViewFrame);
631 //=================================================================
633 * GEOM_Displayer::Redisplay
634 * Redisplay (erase and then display again) interactive object
635 * in the current viewer
637 //=================================================================
638 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
639 const bool updateViewer,
640 const bool checkActiveViewer )
642 bool aRedisplayed = myIsRedisplayed;
643 myIsRedisplayed = true;
644 // Remove the object permanently (<forced> == true)
645 SUIT_Session* ses = SUIT_Session::session();
646 SUIT_Application* app = ses->activeApplication();
649 SUIT_Desktop* desk = app->desktop();
650 QList<SUIT_ViewWindow*> wnds = desk->windows();
651 SUIT_ViewWindow* wnd;
652 QListIterator<SUIT_ViewWindow*> it( wnds );
653 while ( it.hasNext() && (wnd = it.next()) )
655 SUIT_ViewManager* vman = wnd->getViewManager();
658 SUIT_ViewModel* vmodel = vman->getViewModel();
661 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
664 if ( view->isVisible( theIO ) || ( checkActiveViewer && view == GetActiveView() ) )
666 Redisplay( theIO, updateViewer, view );
673 myIsRedisplayed = aRedisplayed;
676 //=================================================================
678 * GEOM_Displayer::Redisplay
679 * Redisplay (erase and then display again) interactive object
680 * in the specified view
682 //=================================================================
683 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
684 const bool theUpdateViewer,
685 SALOME_View* theViewFrame )
687 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
693 bool aRedisplayed = myIsRedisplayed;
694 myIsRedisplayed = true;
695 Erase( theIO, true, false, theViewFrame );
696 Display( theIO, theUpdateViewer, theViewFrame );
697 myIsRedisplayed = aRedisplayed;
698 // hide annotations for erased presentation
699 SUIT_Session* session = SUIT_Session::session();
700 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
701 GeometryGUI* aModule = dynamic_cast<GeometryGUI*>( anApp->activeModule() );
703 if ( !theViewFrame->isVisible( theIO ) ) {
704 aModule->GetAnnotationMgr()->EraseVisibleAnnotations(QString(theIO->getEntry()), dynamic_cast<SOCC_Viewer*>( theViewFrame ));
707 aModule->GetAnnotationMgr()->DisplayVisibleAnnotations(QString(theIO->getEntry()), dynamic_cast<SOCC_Viewer*>( theViewFrame ));
712 //=================================================================
714 * GEOM_Displayer::Display
715 * Calls Display() method for each object in the given list
717 //=================================================================
718 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
720 SALOME_ListIteratorOfListIO Iter( theIOList );
721 for ( ; Iter.More(); Iter.Next() ) {
722 Display( Iter.Value(), false );
728 void GEOM_Displayer::UpdateVisibility( SALOME_View* v, const SALOME_Prs* p, bool on )
730 SalomeApp_Study* aStudy = getStudy();
732 if ( v ) vId = getViewManagerId( v );
735 QString entry = p->GetEntry();
736 if ( !entry.isEmpty() ) {
738 aStudy->setObjectProperty( vId, entry, GEOM::propertyName( GEOM::Visibility ), on );
739 setVisibilityState( entry, on ? Qtx::ShownState : Qtx::HiddenState );
744 aStudy->setObjectProperty( vId, GEOM::propertyName( GEOM::Visibility ), on );
749 Quantity_Color GEOM_Displayer::qColorFromResources( const QString& property, const QColor& defColor )
751 // VSR: this method can be improved in future:
752 // to improve performance, the default values from resource manager should be cached in the displayer
753 return SalomeApp_Tools::color( SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor ) );
756 QColor GEOM_Displayer::colorFromResources( const QString& property, const QColor& defColor )
758 // VSR: this method can be improved in future:
759 // to improve performance, the default values from resource manager should be cached in the displayer
760 return SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor );
763 void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShape, bool create )
765 // check that shape is not null
766 if ( AISShape.IsNull() ) return;
768 // check that study is active
769 SalomeApp_Study* study = getStudy();
770 if ( !study ) return;
772 if ( myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
773 !TopoDS_Iterator(myShape).More() )
774 return; // NPAL15983 (Bug when displaying empty groups)
776 // set interactive object
778 Handle( SALOME_InteractiveObject ) anIO;
780 if ( !myIO.IsNull() ) {
781 AISShape->setIO( myIO );
782 AISShape->SetOwner( myIO );
785 else if ( !myName.empty() ) {
786 // workaround to allow selection of temporary objects
787 static int tempId = 0;
788 anIO = new SALOME_InteractiveObject( QString( "TEMP_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
789 AISShape->setIO( anIO );
790 AISShape->SetOwner( anIO );
793 // flag: only vertex or compound of vertices is processed (specific handling)
794 bool onlyVertex = myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape );
795 // presentation study entry (empty for temporary objects like preview)
796 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
797 // flag: temporary object
798 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
799 // currently active view window's ID (-1 if no active view)
800 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
802 // get presentation properties
803 PropMap propMap = getObjectProperties( entry, myViewFrame );
805 // Temporary staff: vertex must be infinite for correct visualization
806 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
809 Material_Model material;
810 // if predefined color isn't set in displayer(via GEOM_Displayer::SetColor() function)
812 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
813 // - set front material properties
814 AISShape->SetCurrentFacingModel( Aspect_TOFM_FRONT_SIDE );
815 AISShape->SetMaterial( material.getMaterialOCCAspect( true ) );
816 // - set back material properties
817 AISShape->SetCurrentFacingModel( Aspect_TOFM_BACK_SIDE );
818 AISShape->SetMaterial( material.getMaterialOCCAspect( false ) );
819 // - switch to default (both sides) facing mode
820 AISShape->SetCurrentFacingModel( Aspect_TOFM_BOTH_SIDE );
826 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function;
827 // we set it to the shape not taking into account material properties
828 AISShape->SetShadingColor( (Quantity_NameOfColor)GetColor() );
830 else if ( !material.isPhysical() ) {
831 // shading color from properties is used only for non-physical materials
832 AISShape->SetShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>() ) );
836 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
837 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
838 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
839 AISShape->Attributes()->SetLineAspect( anAspect );
841 // - unfree boundaries color
842 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
843 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
844 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
845 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
847 // - free boundaries color
848 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
849 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
850 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>() ) );
851 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
853 // - standalone edges color
854 anAspect = AISShape->Attributes()->WireAspect();
855 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
856 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>() ) );
857 AISShape->Attributes()->SetWireAspect( anAspect );
859 // - color for edges in shading+edges mode
860 AISShape->SetEdgesInShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
862 // - color of labels (textual fields and shape name)
863 AISShape->SetLabelColor( qColorFromResources( "label_color", QColor( 255, 255, 255 ) ) );
866 AISShape->SetDisplayMode( HasDisplayMode() ?
867 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
869 // display mode from properties
870 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt() );
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 = getStudy();
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( entry, myViewFrame );
957 aImagePath = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
960 #ifdef USE_TEXTURED_SHAPE
961 Handle(Image_PixMap) aPixmap;
962 if ( !aImagePath.isEmpty() )
963 aPixmap = cacheTextureFor( aImagePath, AISShape );
965 aPixmap = getDefaultTexture();
967 // apply image to shape
968 if ( !aPixmap.IsNull() ) {
969 AISShape->SetTexturePixMap( aPixmap );
970 AISShape->SetTextureMapOn();
971 AISShape->DisableTextureModulate();
974 AISShape->SetTextureMapOff();
979 AISShape->SetWidth( HasWidth() ?
980 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
982 // libe width from properties
983 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
985 // set top-level flag
986 AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
988 // set point marker (for vertex / compound of vertices only)
989 if ( onlyVertex || isVerticesMode ) {
990 QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
991 if ( aList.size() == 2 ) {
992 // standard marker string contains "TypeOfMarker:ScaleOfMarker"
993 int aTypeOfMarker = aList[0].toInt();
994 double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
995 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
996 anAspect->SetScale( aScaleOfMarker );
997 anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
998 anAspect->SetColor( HasColor() ?
999 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1000 (Quantity_NameOfColor)GetColor() :
1001 // color from properties
1002 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ) );
1003 AISShape->Attributes()->SetPointAspect( anAspect );
1005 else if ( aList.size() == 1 ) {
1006 // custom marker string contains "IdOfTexture"
1007 int textureId = aList[0].toInt();
1008 Standard_Integer aWidth, aHeight;
1009 Handle(TColStd_HArray1OfByte) aTexture =
1010 GeometryGUI::getTexture( textureId, aWidth, aHeight );
1011 if ( !aTexture.IsNull() ) {
1012 Handle(Prs3d_PointAspect) aTextureAspect =
1013 new Prs3d_PointAspect( HasColor() ?
1014 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1015 (Quantity_NameOfColor)GetColor() :
1016 // color from properties
1017 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
1020 AISShape->Attributes()->SetPointAspect( aTextureAspect );
1025 // set field step data
1026 AISShape->setFieldStepInfo( myFieldDataType,
1030 myFieldStepRangeMin,
1031 myFieldStepRangeMax );
1033 if ( create && !isTemporary && aMgrId != -1 ) {
1034 // set properties to the study
1035 study->setObjectProperties( aMgrId, entry, propMap );
1038 // AISShape->SetName(???); ??? necessary to set name ???
1041 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
1043 // check that actor is not null
1044 if ( !actor ) return;
1046 // check that study is active
1047 SalomeApp_Study* study = getStudy();
1048 if ( !study ) return;
1050 // set interactive object
1052 Handle( SALOME_InteractiveObject ) anIO;
1054 if ( !myIO.IsNull() ) {
1055 actor->setIO( myIO );
1058 else if ( !myName.empty() ) {
1059 // workaround to allow selection of temporary objects
1060 static int tempId = 0;
1061 anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
1062 actor->setIO( anIO );
1065 // presentation study entry (empty for temporary objects like preview)
1066 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
1067 // flag: temporary object
1068 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
1069 // currently active view window's ID (-1 if no active view)
1070 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
1072 // get presentation properties
1073 PropMap propMap = getObjectProperties( entry, myViewFrame );
1076 /////////////////////////////////////////////////////////////////////////
1077 // VSR: for VTK viewer currently deflection coefficient is hardcoded
1078 // due to performance problem
1079 // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
1080 /////////////////////////////////////////////////////////////////////////
1081 if ( !actor->getTopo().IsSame( myShape ) )
1082 #ifdef LIMIT_DEFLECTION_FOR_VTK
1083 actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
1085 actor->SetShape( myShape, qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ), myType == GEOM_VECTOR );
1089 Material_Model material;
1090 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
1091 std::vector<vtkProperty*> mprops;
1092 mprops.push_back( material.getMaterialVTKProperty( true ) );
1093 mprops.push_back( material.getMaterialVTKProperty( false) );
1094 actor->SetMaterial( mprops );
1096 // set iso-lines properties
1098 // - set number of iso-lines
1099 int nbIsos[2]= { 1, 1 };
1100 if ( HasNbIsos() ) {
1101 nbIsos[0] = GetNbIsos();
1102 nbIsos[1] = GetNbIsos();
1105 QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
1106 nbIsos[0] = isos[0].toInt();
1107 nbIsos[1] = isos[1].toInt();
1109 actor->SetNbIsos( nbIsos );
1111 // - set iso-lines width
1112 actor->SetIsosWidth( HasIsosWidth() ? GetIsosWidth() : propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
1114 // - set iso-lines color
1115 if ( HasIsosColor() )
1116 c = SalomeApp_Tools::color( Quantity_Color((Quantity_NameOfColor)GetIsosColor()) );
1118 c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
1119 actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
1124 // - same color for all sub-actors
1125 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1126 actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1129 // shading color (for non-physical materials)
1130 if ( !material.isPhysical() ) {
1131 c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
1132 actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1133 actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1136 // - standalone edge color
1137 c = propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>();
1138 actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1140 c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
1141 // - shared edges color ???
1142 actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1144 c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
1145 // - free edges color ???
1146 actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
1149 c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
1150 actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
1153 // - color for edges in shading+edges mode
1154 c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
1155 actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
1157 // - color of labels (shape name)
1158 c = colorFromResources( "label_color", QColor( 255, 255, 255 ) );
1159 actor->SetLabelColor( c.redF(), c.greenF(), c.blueF() );
1162 if( HasTransparency() ) {
1163 actor->SetOpacity( 1.0 - GetTransparency() );
1165 actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
1169 actor->SetWidth( HasWidth() ?
1170 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1172 // libe width from properties
1173 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
1175 // set display vectors flag
1176 actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
1178 // set display vertices flag
1179 actor->SetVerticesMode( propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool() );
1181 // set display name flag
1182 actor->SetNameMode( propMap.value( GEOM::propertyName( GEOM::ShowName ) ).toBool() );
1185 int displayMode = HasDisplayMode() ?
1186 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
1188 // display mode from properties
1189 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
1191 // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
1192 // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
1193 // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
1194 // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
1196 if ( displayMode == 2 )
1197 // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
1198 // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
1200 actor->setDisplayMode( displayMode );
1203 actor->PickableOn();
1205 actor->PickableOff();
1207 if ( create && !isTemporary && aMgrId != -1 ) {
1208 // set properties to the study
1209 study->setObjectProperties( aMgrId, entry, propMap );
1213 //=================================================================
1215 * GEOM_Displayer::updateDimensions
1216 * Creates or renews dimension presentation for the IO.
1218 //=================================================================
1219 void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& theIO,
1220 SALOME_OCCPrs* thePrs,
1221 const gp_Ax3& theShapeLCS )
1223 SalomeApp_Study* aStudy = getStudy();
1229 if ( theIO.IsNull() )
1234 SOCC_Prs* anOccPrs = dynamic_cast<SOCC_Prs*>( thePrs );
1236 AIS_ListOfInteractive aListOfIO;
1238 anOccPrs->GetObjects( aListOfIO );
1240 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
1242 // remove outdated presentations of dimensions
1243 for ( ; aIterateIO.More(); aIterateIO.Next() )
1245 const Handle(AIS_InteractiveObject)& anIO = aIterateIO.Value();
1246 if ( !anIO->IsKind( STANDARD_TYPE( AIS_Dimension ) ) )
1251 aListOfIO.Remove( aIterateIO );
1253 if ( !aIterateIO.More() )
1259 // prepare dimension styling
1260 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1262 QColor aQColor = aResMgr->colorValue ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
1263 int aLineWidth = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
1264 QFont aFont = aResMgr->fontValue ( "Geometry", "dimensions_font", QFont("Y14.5M-2009", 14) );
1265 double anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
1266 bool isUnitsShown = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
1267 QString aUnitsLength = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
1268 QString aUnitsAngle = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
1269 bool aUseText3d = aResMgr->booleanValue( "Geometry", "dimensions_use_text3d", false );
1271 // restore dimension presentation from saved attribute or property data
1272 AIS_ListOfInteractive aRestoredDimensions;
1274 QVariant aProperty = aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1276 GEOM::propertyName( GEOM::Dimensions ),
1279 GEOMGUI_DimensionProperty aRecords;
1281 if ( aProperty.isValid() && aProperty.canConvert<GEOMGUI_DimensionProperty>() )
1283 aRecords = aProperty.value<GEOMGUI_DimensionProperty>();
1287 aRecords.LoadFromAttribute( theIO->getEntry() );
1290 // create up-to-date dimension presentations
1291 for ( int aPrsIt = 0; aPrsIt < aRecords.GetNumber(); ++aPrsIt )
1293 if ( !aRecords.IsVisible( aPrsIt ) )
1298 // init dimension by type
1299 Handle(AIS_Dimension) aPrs;
1300 switch( aRecords.GetType( aPrsIt ) )
1302 case GEOMGUI_DimensionProperty::DimensionType_Length :
1304 Handle(GEOM_AISLength) aLength = new GEOM_AISLength( aPrsIt );
1305 aRecords.GetRecord( aPrsIt )->AsLength()->Update( aLength, theShapeLCS );
1310 case GEOMGUI_DimensionProperty::DimensionType_Diameter :
1312 Handle(GEOM_AISDiameter) aDiam = new GEOM_AISDiameter( aPrsIt );
1313 aRecords.GetRecord( aPrsIt )->AsDiameter()->Update( aDiam, theShapeLCS );
1318 case GEOMGUI_DimensionProperty::DimensionType_Angle :
1320 Handle(GEOM_AISAngle) anAng = new GEOM_AISAngle( aPrsIt );
1321 aRecords.GetRecord( aPrsIt )->AsAngle()->Update( anAng, theShapeLCS );
1327 aPrs->SetOwner( theIO );
1329 Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
1331 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
1333 aStyle->SetCommonColor( aColor );
1334 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1335 aStyle->MakeText3d( aUseText3d );
1336 aStyle->MakeTextShaded( Standard_True );
1337 int fsize = aFont.pixelSize() != -1 ? aFont.pixelSize() : aFont.pointSize();
1338 aStyle->SetExtensionSize( fsize * 0.5 );
1339 aStyle->TextAspect()->SetFont( aFont.family().toLatin1().data() );
1340 aStyle->TextAspect()->SetHeight( fsize );
1341 aStyle->ArrowAspect()->SetLength( anArrowLength );
1342 aStyle->LineAspect()->SetWidth( aLineWidth );
1343 aStyle->SetTextHorizontalPosition( aPrs->DimensionAspect()->TextHorizontalPosition() );
1344 aStyle->SetTextVerticalPosition( aPrs->DimensionAspect()->TextVerticalPosition() );
1345 aStyle->SetArrowOrientation( aPrs->DimensionAspect()->ArrowOrientation() );
1346 aPrs->SetDimensionAspect( aStyle );
1347 aPrs->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
1348 aPrs->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
1349 aPrs->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
1351 if ( aPrs->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
1353 // show degree symbol for dimension instead of label "deg"
1354 if ( aUnitsAngle == "deg" )
1356 aPrs->SetSpecialSymbol(0xB0);
1357 aPrs->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
1358 aStyle->MakeUnitsDisplayed(Standard_False);
1362 aPrs->SetDisplaySpecialSymbol(AIS_DSS_No);
1363 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1368 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1371 aListOfIO.Append( aPrs );
1374 // update presentation
1377 for ( aIterateIO.Initialize( aListOfIO ); aIterateIO.More(); aIterateIO.Next() )
1379 anOccPrs->AddObject( aIterateIO.Value() );
1383 //=================================================================
1385 * GEOM_Displayer::Erase
1386 * Calls Erase() method for each object in the given list
1388 //=================================================================
1389 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
1391 const bool updateViewer )
1393 SALOME_ListIteratorOfListIO Iter( theIOList );
1394 for ( ; Iter.More(); Iter.Next() )
1395 Erase( Iter.Value(), forced, false );
1401 //=================================================================
1403 * GEOM_Displayer::Redisplay
1404 * Calls Redisplay() method for each object in the given list
1406 //=================================================================
1407 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1408 const bool updateViewer,
1409 const bool checkActiveViewer )
1411 SALOME_ListIteratorOfListIO Iter( theIOList );
1412 for ( ; Iter.More(); Iter.Next() )
1413 Redisplay( Iter.Value(), false, checkActiveViewer );
1419 //=================================================================
1421 * GEOM_Displayer::Redisplay
1422 * Calls Redisplay() method for each object in the given list
1424 //=================================================================
1425 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1426 const bool theUpdateViewer,
1427 SALOME_View* theViewFrame )
1429 SALOME_ListIteratorOfListIO anIter( theIOList );
1430 for ( ; anIter.More(); anIter.Next() )
1432 Redisplay( anIter.Value(), false, theViewFrame );
1435 if ( theUpdateViewer )
1441 //=================================================================
1443 * GEOM_Displayer::Update
1444 * Update OCC presentaion
1445 * [ Reimplemented from SALOME_Displayer ]
1447 //=================================================================
1448 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
1450 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
1451 SalomeApp_Study* study = getStudy();
1453 if ( !occPrs || myShape.IsNull() || !study )
1456 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1459 // specific processing for local coordinate system presentation
1462 TopoDS_Face aFace = TopoDS::Face( myShape );
1463 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1464 if ( !aPlane.IsNull() )
1466 gp_Ax3 aPos = aPlane->Pln().Position();
1467 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1469 Handle(GEOM_AISTrihedron) aTrh;
1471 if ( occPrs->IsNull() )
1473 // new presentation is being created
1474 aTrh = new GEOM_AISTrihedron( aPlc );
1475 occPrs->AddObject( aTrh );
1479 // presentation is being updated
1480 AIS_ListOfInteractive aList;
1481 occPrs->GetObjects( aList );
1482 AIS_ListIteratorOfListOfInteractive anIter( aList );
1483 for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
1484 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
1488 if ( !aTrh.IsNull() ) {
1489 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1491 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1492 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1494 aTrh->SetWidth( GetWidth() );
1496 if ( !myIO.IsNull() )
1498 aTrh->setIO( myIO );
1499 aTrh->SetOwner( myIO );
1501 aTrh->SetComponent( aPlc );
1502 aTrh->SetToUpdate();
1504 occPrs->SetToActivate( ToActivate() );
1510 // processing for usual geometry presentation
1513 // if presentation is empty we try to create new one
1514 if ( occPrs->IsNull() )
1516 // create presentation (specific for vectors)
1517 Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1518 : new GEOM_AISShape ( myShape, "" );
1520 if( myType == GEOM_FIELD_STEP )
1521 AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight );
1522 // update shape properties
1523 updateShapeProperties( AISShape, true );
1525 // add shape to the presentation
1526 occPrs->AddObject( AISShape );
1528 // In accordance with ToActivate() value object will be activated/deactivated
1529 // when it will be displayed
1530 occPrs->SetToActivate( ToActivate() );
1532 if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1533 // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1535 // create additional wireframe shape
1536 Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1537 aWirePrs->SetWidth(AISShape->Width());
1538 if ( !myIO.IsNull() ) {
1539 aWirePrs->setIO( myIO );
1540 aWirePrs->SetOwner( myIO );
1543 // add shape to the presentation
1544 occPrs->AddObject( aWirePrs );
1547 // if presentation is found -> set again shape for it
1550 AIS_ListOfInteractive IOList;
1551 occPrs->GetObjects( IOList );
1552 AIS_ListIteratorOfListOfInteractive Iter( IOList );
1553 for ( ; Iter.More(); Iter.Next() )
1555 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1556 if ( AISShape.IsNull() )
1559 // re-set shape (it might be changed)
1560 if ( AISShape->Shape() != myShape )
1561 AISShape->Set( myShape );
1563 // update shape properties
1564 updateShapeProperties( AISShape, false );
1567 AISShape->UpdateSelection();
1568 AISShape->SetToUpdate();
1572 updateDimensions( myIO, occPrs, gp_Ax3().Transformed( myShape.Location().Transformation() ) );
1576 //=================================================================
1578 * GEOM_Displayer::Update
1579 * Update VTK presentaion
1580 * [ Reimplemented from SALOME_Displayer ]
1582 //=================================================================
1583 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1585 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1586 SalomeApp_Study* study = getStudy();
1588 if ( !vtkPrs || myShape.IsNull() || !study )
1591 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1594 // specific processing for local coordinate system presentation
1597 TopoDS_Face aFace = TopoDS::Face( myShape );
1598 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1599 if ( !aPlane.IsNull() ) {
1600 gp_Ax3 aPos = aPlane->Pln().Position();
1601 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1603 GEOM_VTKTrihedron* aTrh = 0;
1605 if ( vtkPrs->IsNull() ) {
1606 // new presentation is being created
1607 aTrh = GEOM_VTKTrihedron::New();
1608 vtkPrs->AddObject( aTrh );
1611 // presentation is being updated
1612 vtkActorCollection* actors = vtkPrs->GetObjects();
1614 actors->InitTraversal();
1615 vtkActor* a = actors->GetNextActor();
1616 while ( a && !aTrh ) {
1617 aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1618 a = actors->GetNextActor();
1624 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1626 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1627 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1629 #ifdef VTK_TRIHEDRON_WIDTH
1631 // VSR: currently isn't supported
1633 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1635 aTrh->SetWidth( GetWidth() );
1638 if ( !myIO.IsNull() )
1639 aTrh->setIO( myIO );
1641 aTrh->SetPlacement( aPlc );
1648 // processing for usual geometry presentation
1651 // if presentation is empty we try to create new one
1652 if ( vtkPrs->IsNull() )
1655 GEOM_Actor* actor = GEOM_Actor::New();
1656 // update actor properties
1657 updateActorProperties( actor, true );
1658 // add actor to the presentation
1659 vtkPrs->AddObject( actor );
1662 // presentation is being updated
1663 vtkActorCollection* actors = vtkPrs->GetObjects();
1665 actors->InitTraversal();
1666 vtkActor* a = actors->GetNextActor();
1668 GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1670 // update actor properties
1671 updateActorProperties( actor, false );
1672 a = actors->GetNextActor();
1680 //=================================================================
1682 * GEOM_Displayer::BuildPrs
1683 * Build presentation accordint to the current viewer type
1685 //=================================================================
1686 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1688 if ( theObj->_is_nil() )
1691 myViewFrame = GetActiveView();
1692 if ( myViewFrame == 0 )
1695 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1700 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1701 myType = theObj->GetType();
1703 // Update presentation
1709 //=================================================================
1711 * GEOM_Displayer::BuildPrs
1712 * Build presentation accordint to the current viewer type
1714 //=================================================================
1715 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1717 myViewFrame = GetActiveView();
1718 if ( theShape.IsNull() || myViewFrame == 0 )
1721 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1726 setShape( theShape );
1734 //=================================================================
1736 * GEOM_Displayer::buildPresentation
1737 * Builds/finds object's presentation for the current viewer
1738 * Calls corresponding Update() method by means of double dispatch
1741 //=================================================================
1742 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1743 SALOME_View* theViewFrame )
1745 SALOME_Prs* prs = 0;
1748 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1752 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1755 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1756 theIO->setEntry( entry.toLatin1().constData() );
1757 if ( !theIO.IsNull() )
1759 // set interactive object
1761 // Find SOBject (because shape should be published previously)
1764 _PTR(SObject) SO ( getStudy()->studyDS()->FindObjectID( theIO->getEntry() ) );
1767 // get CORBA reference to data object
1768 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1769 if ( !CORBA::is_nil( object ) )
1771 // downcast to GEOM base object
1772 GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
1773 if ( !GeomBaseObject->_is_nil() )
1775 myType = GeomBaseObject->GetType();
1777 // downcast to GEOM object
1778 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
1779 if ( myType == GEOM_FIELD_STEP )
1781 // get the GEOM object from the field's shape
1782 GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
1783 if ( !GeomFieldStep->_is_nil() )
1785 GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
1786 if ( !GeomField->_is_nil() )
1787 GeomObject = GeomField->GetShape();
1790 // read the field step information
1791 readFieldStepInfo( GeomFieldStep );
1794 if ( !GeomObject->_is_nil() )
1796 theIO->setName( GeomObject->GetName() );
1797 // finally set shape
1798 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1805 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1811 //=================================================================
1813 * GEOM_Displayer::buildSubshapePresentation
1814 * Builds/finds object's presentation for the current viewer
1815 * Calls corresponding Update() method by means of double dispatch
1816 * For not published objects (for Mantis issue 0020435)
1818 //=================================================================
1819 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1820 const QString& entry,
1821 SALOME_View* theViewFrame)
1823 SALOME_Prs* prs = 0;
1826 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1830 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1833 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1834 theIO->setEntry(entry.toLatin1().constData());
1835 if (!theIO.IsNull())
1837 // set interactive object
1839 // finally set shape
1841 myType = GEOM_SUBSHAPE;
1843 UpdatePrs(prs); // Update presentation by using of the double dispatch
1849 //=================================================================
1851 * GEOM_Displayer::internalReset
1852 * Resets internal data
1855 //=================================================================
1856 void GEOM_Displayer::internalReset()
1861 myFieldDataType = GEOM::FDT_Double;
1862 myFieldDimension = 0;
1863 myFieldStepData.clear();
1864 myFieldStepName.Clear();
1865 myFieldStepRangeMin = 0;
1866 myFieldStepRangeMax = 0;
1869 //=================================================================
1871 * GEOM_Displayer::LocalSelection
1872 * Activate selection of CAD shapes with activisation of selection
1873 * of their sub-shapes (with opened local context for OCC viewer)
1875 //=================================================================
1876 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const std::list<int> modes )
1878 SUIT_Session* session = SUIT_Session::session();
1879 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1883 LightApp_SelectionMgr* sm = app->selectionMgr();
1885 // remove all filters from selection
1888 SALOME_View* vf = GetActiveView();
1890 if (!theIO.IsNull() && !vf->isVisible(theIO))
1892 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1893 vf->LocalSelection( prs, modes );
1894 delete prs; // delete presentation because displayer is its owner
1898 //=================================================================
1900 * GEOM_Displayer::LocalSelection
1901 * Activate selection of CAD shapes with activisation of selection
1902 * of their sub-shapes (with opened local context for OCC viewer)
1904 //=================================================================
1905 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1907 std::list<int> modes;
1908 modes.push_back( theMode );
1909 LocalSelection( theIO, modes );
1912 //=================================================================
1914 * GEOM_Displayer::globalSelection
1915 * Activate selection of CAD shapes without activisation of selection
1916 * of their sub-shapes (without opened local context for OCC viewer)
1918 //=================================================================
1919 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1921 TColStd_MapOfInteger aModes;
1922 aModes.Add( theMode );
1923 GlobalSelection( aModes, update );
1926 //=================================================================
1928 * GEOM_Displayer::globalSelection
1929 * Activate selection of CAD shapes without activisation of selection
1930 * of their sub-shapes (without opened local context for OCC viewer)
1932 //=================================================================
1933 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1934 const bool update, const QList<int>* theSubShapes )
1936 SUIT_Session* session = SUIT_Session::session();
1937 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1941 SALOME_View* vf = GetActiveView();
1945 // Close local context
1946 vf->GlobalSelection( update );
1948 // Set selection filters in accordance with current mode
1949 LightApp_SelectionMgr* sm = app->selectionMgr();
1953 // Remove from selection temporary objects if necessary
1954 if ( !theModes.Contains( GEOM_PREVIEW ) )
1955 clearTemporary( sm );
1957 //@ aSel->ClearIndex();
1961 // Remove filters from AIS_InteractiveContext
1962 Handle(AIS_InteractiveContext) ic;
1963 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1966 ic = viewer->getAISContext();
1968 ic->RemoveFilters();
1971 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1974 SUIT_SelectionFilter* aFilter;
1975 if ( theModes.Extent() == 1 )
1977 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1979 if ( aMode == GEOM_COMPOUNDFILTER )
1980 aFilter = getComplexFilter( theSubShapes );
1982 aFilter = getFilter( aMode );
1984 else if ( theModes.Extent() > 1 )
1986 TColStd_MapOfInteger aTopAbsModes;
1987 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1988 QList<SUIT_SelectionFilter*> aListOfFilters;
1989 for ( ; anIter.More(); anIter.Next() )
1991 SUIT_SelectionFilter* aFilter;
1992 int aMode = anIter.Key();
1993 if ( aMode == GEOM_COMPOUNDFILTER )
1994 aFilter = getComplexFilter( theSubShapes );
1996 aFilter = getFilter( aMode );
1999 aListOfFilters.append( aFilter );
2002 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
2009 sm->installFilter( aFilter );
2012 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
2013 ic->AddFilter( anOCCFilter );
2018 //=================================================================
2020 * GEOM_Displayer::LocalSelection
2021 * Activate selection of CAD shapes with activisation of selection
2022 * of their sub-shapes (with opened local context for OCC viewer)
2024 //=================================================================
2025 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const std::list<int> modes )
2027 SALOME_ListIteratorOfListIO Iter( theIOList );
2028 for ( ; Iter.More(); Iter.Next() )
2029 LocalSelection( Iter.Value(), modes );
2032 //=================================================================
2034 * GEOM_Displayer::LocalSelection
2035 * Activate selection of CAD shapes with activisation of selection
2036 * of their sub-shapes (with opened local context for OCC viewer)
2038 //=================================================================
2039 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
2041 std::list<int> modes;
2042 modes.push_back( theMode );
2043 LocalSelection( theIOList, modes );
2046 //=================================================================
2048 * GEOM_Displayer::BeforeDisplay
2049 * Called before displaying of pars. Close local context
2050 * [ Reimplemented from SALOME_Displayer ]
2052 //=================================================================
2053 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
2055 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
2058 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
2061 if ( ic->HasOpenedContext() )
2062 ic->CloseAllContexts(Standard_True);
2067 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
2069 UpdateColorScale(false,false);
2071 // visualize annotations for displayed presentation
2072 SUIT_Session* session = SUIT_Session::session();
2073 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2074 GeometryGUI* aModule = dynamic_cast<GeometryGUI*>( anApp->activeModule() );
2076 if ( !myIsRedisplayed ) {
2077 aModule->GetAnnotationMgr()->DisplayVisibleAnnotations(QString(p->GetEntry()), dynamic_cast<SOCC_Viewer*>( v ));
2079 aModule->GetAnnotationMgr()->UpdateVisibleAnnotations(QString(p->GetEntry()), dynamic_cast<SOCC_Viewer*>( v ));
2084 void GEOM_Displayer::BeforeErase( SALOME_View* v, const SALOME_OCCPrs* p )
2086 LightApp_Displayer::BeforeErase( v, p );
2087 releaseTextures( p );
2090 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
2092 LightApp_Displayer::AfterErase( v, p );
2093 UpdateColorScale(false,false);
2095 if ( !myIsRedisplayed ) {
2096 // hide annotations for erased presentation
2097 SUIT_Session* session = SUIT_Session::session();
2098 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2099 GeometryGUI* aModule = dynamic_cast<GeometryGUI*>( anApp->activeModule() );
2101 aModule->GetAnnotationMgr()->EraseVisibleAnnotations(QString(p->GetEntry()), dynamic_cast<SOCC_Viewer*>( v ));
2105 //=================================================================
2107 * GEOM_Displayer::SetColor
2108 * Set color for shape displaying. If it is equal -1 then default color is used.
2109 * Available values are from Quantity_NameOfColor enumeration
2111 //=================================================================
2112 void GEOM_Displayer::SetColor( const int color )
2119 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
2123 int GEOM_Displayer::GetColor() const
2128 bool GEOM_Displayer::HasColor() const
2130 return myColor != -1;
2133 void GEOM_Displayer::UnsetColor()
2137 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2138 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
2139 myShadingColor = SalomeApp_Tools::color( col );
2142 //=================================================================
2144 * GEOM_Displayer::SetTransparency
2145 * Set transparency for shape displaying.
2147 //=================================================================
2148 double GEOM_Displayer::SetTransparency( const double transparency )
2150 double prevTransparency = myTransparency;
2151 myTransparency = transparency;
2152 return prevTransparency;
2155 //=================================================================
2157 * GEOM_Displayer::GetTransparency
2158 * Get transparency for shape displaying.
2160 //=================================================================
2161 double GEOM_Displayer::GetTransparency() const
2163 return myTransparency;
2166 //=================================================================
2168 * GEOM_Displayer::HasTransparency
2169 * Check if transparency for shape displaying is set.
2171 //=================================================================
2172 bool GEOM_Displayer::HasTransparency() const
2174 return myTransparency >= 0;
2177 //=================================================================
2179 * GEOM_Displayer::UnsetTransparency
2180 * Unset transparency for shape displaying.
2182 //=================================================================
2183 double GEOM_Displayer::UnsetTransparency()
2185 return SetTransparency( -1 );
2188 //=================================================================
2190 * GEOM_Displayer::SetTexture
2192 //=================================================================
2193 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
2195 myTexture = texureFileName;
2198 bool GEOM_Displayer::HasTexture() const
2200 return myTexture != "";
2203 std::string GEOM_Displayer::GetTexture() const
2208 //=================================================================
2210 * GEOM_Displayer::SetWidth
2211 * Set width of shape displaying. If it is equal -1 then default width is used.
2213 //=================================================================
2214 void GEOM_Displayer::SetWidth( const double width )
2219 double GEOM_Displayer::GetWidth() const
2224 bool GEOM_Displayer::HasWidth() const
2226 return myWidth != -1;
2229 void GEOM_Displayer::UnsetWidth()
2234 int GEOM_Displayer::GetIsosWidth() const
2239 void GEOM_Displayer::SetIsosWidth(const int width)
2241 myIsosWidth = width;
2244 bool GEOM_Displayer::HasIsosWidth() const
2246 return myIsosWidth != -1;
2249 int GEOM_Displayer::SetNbIsos( const int nbIsos )
2251 int prevNbIsos = myNbIsos;
2256 int GEOM_Displayer::UnsetNbIsos()
2258 return SetNbIsos( -1 );
2261 int GEOM_Displayer::GetNbIsos() const
2266 bool GEOM_Displayer::HasNbIsos() const
2268 return myNbIsos >= 0;
2271 int GEOM_Displayer::SetIsosColor( const int color )
2273 int prevColor = myIsosColor;
2274 myIsosColor = color;
2278 int GEOM_Displayer::GetIsosColor() const
2283 bool GEOM_Displayer::HasIsosColor() const
2285 return myIsosColor != -1;
2288 int GEOM_Displayer::UnsetIsosColor()
2290 return SetIsosColor( -1 );
2293 //=================================================================
2295 * GEOM_Displayer::SetToActivate
2296 * This method is used for activisation/deactivisation of objects to be displayed
2298 //=================================================================
2299 void GEOM_Displayer::SetToActivate( const bool toActivate )
2301 myToActivate = toActivate;
2303 bool GEOM_Displayer::ToActivate() const
2305 return myToActivate;
2308 //=================================================================
2310 * GEOM_Displayer::clearTemporary
2311 * Removes from selection temporary objects
2313 //=================================================================
2314 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
2316 SALOME_ListIO selected, toSelect;
2317 theSelMgr->selectedObjects( selected );
2319 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
2320 Handle(SALOME_InteractiveObject) io = it.Value();
2321 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
2322 toSelect.Append( it.Value() );
2325 theSelMgr->setSelectedObjects( toSelect, true );
2328 void GEOM_Displayer::SetName( const char* theName )
2333 void GEOM_Displayer::UnsetName()
2338 SalomeApp_Study* GEOM_Displayer::getStudy() const
2340 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2343 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
2348 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
2353 void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
2354 const int theFieldDimension,
2355 const QList<QVariant>& theFieldStepData,
2356 const TCollection_AsciiString& theFieldStepName,
2357 const double theFieldStepRangeMin,
2358 const double theFieldStepRangeMax )
2360 myFieldDataType = theFieldDataType;
2361 myFieldDimension = theFieldDimension;
2362 myFieldStepData = theFieldStepData;
2363 myFieldStepName = theFieldStepName;
2364 myFieldStepRangeMin = theFieldStepRangeMin;
2365 myFieldStepRangeMax = theFieldStepRangeMax;
2368 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
2370 _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
2371 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
2372 GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
2373 GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
2374 return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
2375 (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
2378 int GEOM_Displayer::SetDisplayMode( const int theMode )
2380 int aPrevMode = myDisplayMode;
2381 if ( theMode != -1 ) {
2382 myDisplayMode = theMode;
2383 myHasDisplayMode = true;
2391 int GEOM_Displayer::GetDisplayMode() const
2393 return myDisplayMode;
2396 int GEOM_Displayer::UnsetDisplayMode()
2398 int aPrevMode = myDisplayMode;
2399 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2400 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
2401 myHasDisplayMode = false;
2405 bool GEOM_Displayer::HasDisplayMode() const
2407 return myHasDisplayMode;
2410 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
2412 static QList<QColor> colors;
2414 if ( colors.isEmpty() ) {
2416 for (int s = 0; s < 2 ; s++)
2418 for (int v = 100; v >= 40; v = v - 20)
2420 for (int h = 0; h < 359 ; h = h + 60)
2422 colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
2428 static int currentColor = randomize( colors.size() );
2430 SALOMEDS::Color color;
2431 color.R = (double)colors[currentColor].red() / 255.0;
2432 color.G = (double)colors[currentColor].green() / 255.0;
2433 color.B = (double)colors[currentColor].blue() / 255.0;
2435 currentColor = (currentColor+1) % colors.count();
2440 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
2443 int aTolerance = 64;
2444 int anIterations = 0;
2450 if( anIterations % aPeriod == 0 )
2453 if( aTolerance < 1 )
2456 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
2458 aHue = (int)( 360.0 * rand() / RAND_MAX );
2459 //std::cout << "Hue = " << aHue << std::endl;
2461 //std::cout << "Auto colors : ";
2463 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
2464 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
2465 for( ; it != itEnd; ++it )
2467 SALOMEDS::Color anAutoColor = *it;
2468 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
2471 aQColor.getHsv( &h, &s, &v );
2472 //std::cout << h << " ";
2473 if( abs( h - aHue ) < aTolerance )
2476 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
2480 //std::cout << std::endl;
2486 //std::cout << "Hue of the returned color = " << aHue << std::endl;
2488 aColor.setHsv( aHue, 255, 255 );
2490 SALOMEDS::Color aSColor;
2491 aSColor.R = (double)aColor.red() / 255.0;
2492 aSColor.G = (double)aColor.green() / 255.0;
2493 aSColor.B = (double)aColor.blue() / 255.0;
2498 PropMap GEOM_Displayer::getObjectProperties( const QString& entry,
2501 // get default properties for the explicitly specified default view type
2502 PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
2504 if ( getStudy() && view ) {
2505 SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
2506 SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
2507 int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
2509 if ( viewModel && viewId != -1 ) {
2510 // get properties from the study
2511 PropMap storedMap = getStudy()->getObjectProperties( viewId, entry );
2512 // overwrite default properties from stored ones (that are specified)
2513 for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
2514 if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
2515 propMap.insert( GEOM::propertyName( (GEOM::Property)prop ),
2516 storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
2518 // ... specific processing for color
2519 // ... current implementation is to use same stored color for all aspects
2520 // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2521 if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2522 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2523 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2524 propMap.insert( GEOM::propertyName( GEOM::LineColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2525 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2526 propMap.insert( GEOM::propertyName( GEOM::PointColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2529 if ( !entry.isEmpty() ) {
2530 // get CORBA reference to geom object
2531 _PTR(SObject) SO( getStudy()->studyDS()->FindObjectID( entry.toStdString() ) );
2533 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
2534 if ( !CORBA::is_nil( object ) ) {
2535 GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
2536 if ( !CORBA::is_nil( geomObject ) ) { // to check
2537 // check that geom object has color properly set
2538 bool hasColor = false;
2539 SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
2540 // set color from geometry object (only once, if it is not yet set in GUI)
2541 // current implementation is to use same color for all aspects
2542 // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2543 if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2544 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
2545 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), objColor );
2546 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
2547 propMap.insert( GEOM::propertyName( GEOM::LineColor ), objColor );
2548 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), objColor );
2549 propMap.insert( GEOM::propertyName( GEOM::PointColor ), objColor );
2551 // check that object has point marker properly set
2552 GEOM::marker_type mType = geomObject->GetMarkerType();
2553 GEOM::marker_size mSize = geomObject->GetMarkerSize();
2554 int mTextureId = geomObject->GetMarkerTexture();
2555 bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) ||
2556 ( mType == GEOM::MT_USER && mTextureId > 0 );
2557 // set point marker from geometry object (only once, if it is not yet set in GUI)
2558 if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
2559 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
2561 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2562 QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
2564 else if ( mType == GEOM::MT_USER ) {
2566 propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
2578 PropMap GEOM_Displayer::getDefaultPropertyMap()
2582 // get resource manager
2583 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2585 // fill in the properties map with default values
2587 // - visibility (false by default)
2588 propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
2590 // - nb isos (take default value from preferences)
2591 propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
2592 QString( "%1%2%3" ).
2593 arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
2594 arg( GEOM::subSectionSeparator() ).
2595 arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
2597 // - transparency (opacity = 1-transparency)
2598 propMap.insert( GEOM::propertyName( GEOM::Transparency ),
2599 resMgr->integerValue( "Geometry", "transparency", 0 ) / 100. );
2601 // - display mode (take default value from preferences)
2602 propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
2603 resMgr->integerValue( "Geometry", "display_mode", 0 ) );
2605 // - show edges direction flag (false by default)
2606 propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
2608 // - show vertices flag (false by default)
2609 propMap.insert( GEOM::propertyName( GEOM::Vertices ), false );
2611 // - show name flag (false by default)
2612 propMap.insert( GEOM::propertyName( GEOM::ShowName ), false );
2614 // - shading color (take default value from preferences)
2615 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
2616 colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
2618 // - wireframe color (take default value from preferences)
2619 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
2620 colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
2622 // - standalone edges color (take default value from preferences)
2623 propMap.insert( GEOM::propertyName( GEOM::LineColor ),
2624 colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
2626 // - free boundaries color (take default value from preferences)
2627 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
2628 colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
2630 // - points color (take default value from preferences)
2631 propMap.insert( GEOM::propertyName( GEOM::PointColor ),
2632 colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
2634 // - isos color (take default value from preferences)
2635 propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
2636 colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
2638 // - outlines color (take default value from preferences)
2639 propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
2640 colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
2642 // - deflection coefficient (take default value from preferences)
2643 propMap.insert( GEOM::propertyName( GEOM::Deflection ),
2644 resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
2646 // - material (take default value from preferences)
2647 Material_Model material;
2648 material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
2649 propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
2651 // - edge width (take default value from preferences)
2652 propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
2653 resMgr->integerValue( "Geometry", "edge_width", 1 ) );
2655 // - isos width (take default value from preferences)
2656 propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
2657 resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
2659 // - point marker (take default value from preferences)
2660 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2661 QString( "%1%2%3" ).
2662 arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
2663 arg( GEOM::subSectionSeparator() ).
2664 arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2666 // - top-level flag (false by default)
2667 propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2672 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2673 SALOMEDS::Color aSColor;
2676 SUIT_Session* session = SUIT_Session::session();
2677 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2679 if ( app && !theGeomObject->_is_nil()) {
2680 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2683 _PTR(Study) aStudy = study->studyDS();
2684 aSColor = theGeomObject->GetColor();
2685 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2687 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2688 bool general_autocolor = true;
2689 #else // auto-color for groups only
2690 bool general_autocolor = false;
2691 #endif // GENERAL_AUTOCOLOR
2692 if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2693 GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2694 if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2695 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2696 aSColor = getPredefinedUniqueColor();
2698 #else // old algorithm for auto-colors
2699 QList<SALOMEDS::Color> aReservedColors;
2700 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2701 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2702 if ( aMainSObject ) {
2703 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2704 for ( ; it->More(); it->Next() ) {
2705 _PTR(SObject) aChildSObject( it->Value() );
2706 GEOM::GEOM_Object_var aChildObject =
2707 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2708 if ( CORBA::is_nil( aChildObject ) )
2711 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2712 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2713 aReservedColors.append( aReservedColor );
2716 aSColor = getUniqueColor( aReservedColors );
2718 #endif // SIMPLE_AUTOCOLOR
2728 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2729 const bool eraseOnlyChildren)
2731 LightApp_DataObject* parent = getStudy()->findObjectByEntry(theIO->getEntry());
2736 // Erase from all views
2737 QList<SALOME_View*> views;
2739 ViewManagerList vmans = myApp->viewManagers();
2740 SUIT_ViewManager* vman;
2741 foreach ( vman, vmans ) {
2742 SUIT_ViewModel* vmod = vman->getViewModel();
2743 view = dynamic_cast<SALOME_View*> ( vmod );
2745 views.append( view );
2748 if( views.count() == 0 )
2751 //Erase childrens w/o update views
2752 DataObjectList listObj = parent->children( true );
2753 SUIT_DataObject* obj;
2754 foreach( obj, listObj ) {
2755 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2757 foreach ( view, views ) {
2758 Handle(SALOME_InteractiveObject) anIO =
2759 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2760 Erase(anIO, false, false, view);
2764 //Erase parent with view update or repaint views
2765 foreach ( view, views ) {
2766 if(!eraseOnlyChildren)
2767 Erase(theIO, false, true, view);
2773 void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
2775 if( theGeomFieldStep->_is_nil() )
2778 GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
2779 if( aGeomField->_is_nil() )
2782 GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
2783 if( aGeomFieldShape->_is_nil() )
2786 TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
2787 TCollection_AsciiString aFieldName( aGeomField->GetName() );
2788 TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
2790 aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
2792 GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
2794 int aFieldDimension = aGeomField->GetDimension();
2796 GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
2797 int aFieldNbComponents = aFieldComponents->length();
2799 QList<QVariant> aFieldStepData;
2800 if( aFieldDataType == GEOM::FDT_Bool )
2802 GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
2803 if ( !aGeomBoolFieldStep->_is_nil() )
2805 GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
2806 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2807 aFieldStepData << (bool)aValues[i];
2810 else if( aFieldDataType == GEOM::FDT_Int )
2812 GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
2813 if ( !aGeomIntFieldStep->_is_nil() )
2815 GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
2816 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2817 aFieldStepData << (qlonglong)aValues[i];
2820 else if( aFieldDataType == GEOM::FDT_Double )
2822 GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
2823 if ( !aGeomDoubleFieldStep->_is_nil() )
2825 GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
2826 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2827 aFieldStepData << (double)aValues[i];
2830 else if( aFieldDataType == GEOM::FDT_String )
2832 GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
2833 if ( !aGeomStringFieldStep->_is_nil() )
2835 GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
2836 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2837 aFieldStepData << QString( aValues[i] );
2841 double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
2842 aFieldStepData = groupFieldData( aFieldStepData,
2844 aFieldDataType == GEOM::FDT_String,
2846 aFieldStepRangeMax );
2848 setFieldStepInfo( aFieldDataType,
2853 aFieldStepRangeMax );
2856 QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
2857 const int theFieldNbComponents,
2858 const bool theIsString,
2859 double& theFieldStepRangeMin,
2860 double& theFieldStepRangeMax )
2862 QList<QVariant> aResultList;
2863 theFieldStepRangeMin = 0;
2864 theFieldStepRangeMax = 0;
2866 if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
2869 int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
2871 QList<QVariant> aGroupedList;
2873 bool anIsBoolean = false;
2874 for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
2877 QStringList aStringList;
2879 int aBaseIndex = aSubShape * theFieldNbComponents;
2880 for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
2882 int anIndex = aComponent + aBaseIndex;
2884 const QVariant& aVariant = theFieldStepData[ anIndex ];
2887 if( aVariant.type() == QVariant::String )
2888 aStringList << aVariant.toString();
2893 if( aVariant.type() == QVariant::Bool )
2895 aValue = aVariant.toBool() ? 1.0 : 0.0;
2901 if( aVariant.type() == QVariant::LongLong )
2902 aValue = double( aVariant.toLongLong() );
2903 else if( aVariant.type() == QVariant::Double )
2904 aValue = aVariant.toDouble();
2905 aNorm += aValue * aValue;
2911 aGroupedList << aStringList.join( "\n" );
2915 aNorm /= theFieldNbComponents;
2917 aNorm = pow( aNorm, 0.5 );
2919 if( aGroupedList.isEmpty() )
2920 theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
2923 theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
2924 theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
2927 aGroupedList << aNorm;
2933 theFieldStepRangeMin = 0.0;
2934 theFieldStepRangeMax = 1.0;
2937 SUIT_Session* session = SUIT_Session::session();
2938 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2939 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2941 QListIterator<QVariant> anIter( aGroupedList );
2942 while( anIter.hasNext() )
2944 const QVariant& aVariant = anIter.next();
2946 aResultList << aVariant;
2950 Quantity_Color aColor;
2951 #if OCC_VERSION_MAJOR < 7
2952 if( FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2954 if( AIS_ColorScale::FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2956 aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
2957 aResultList << aQColor;
2963 #if OCC_VERSION_MAJOR < 7
2964 // Note: the method is copied from Aspect_ColorScale class
2965 Standard_Integer GEOM_Displayer::HueFromValue( const Standard_Integer aValue,
2966 const Standard_Integer aMin,
2967 const Standard_Integer aMax )
2969 Standard_Integer minLimit( 0 ), maxLimit( 230 );
2971 Standard_Integer aHue = maxLimit;
2973 aHue = (Standard_Integer)( maxLimit - ( maxLimit - minLimit ) * ( aValue - aMin ) / ( aMax - aMin ) );
2975 aHue = Min( Max( minLimit, aHue ), maxLimit );
2980 // Note: the method is copied from Aspect_ColorScale class
2981 Standard_Boolean GEOM_Displayer::FindColor( const Standard_Real aValue,
2982 const Standard_Real aMin,
2983 const Standard_Real aMax,
2984 const Standard_Integer ColorsCount,
2985 Quantity_Color& aColor )
2987 if( aValue<aMin || aValue>aMax || aMax<aMin )
2988 return Standard_False;
2992 Standard_Real IntervNumber = 0;
2995 else if( aValue>aMax )
2996 IntervNumber = ColorsCount-1;
2997 else if( Abs( aMax-aMin ) > Precision::Approximation() )
2998 IntervNumber = Floor( Standard_Real( ColorsCount ) * ( aValue - aMin ) / ( aMax - aMin ) ); // 'Ceiling' replaced with 'Floor'
3000 Standard_Integer Interv = Standard_Integer( IntervNumber );
3002 aColor = Quantity_Color( HueFromValue( Interv, 0, ColorsCount - 1 ), 1.0, 1.0, Quantity_TOC_HLS );
3004 return Standard_True;
3009 void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, const bool updateViewer )
3011 SOCC_Viewer* aViewModel = dynamic_cast<SOCC_Viewer*>( GetActiveView() );
3015 Handle(V3d_Viewer) aViewer = aViewModel->getViewer3d();
3016 if( aViewer.IsNull() )
3019 aViewer->InitActiveViews();
3020 if( !aViewer->MoreActiveViews() )
3023 Handle(V3d_View) aView = aViewer->ActiveView();
3024 if( aView.IsNull() )
3027 Standard_Boolean anIsDisplayColorScale = Standard_False;
3028 TCollection_AsciiString aColorScaleTitle;
3029 Standard_Real aColorScaleMin = 0, aColorScaleMax = 0;
3030 Standard_Boolean anIsBoolean = Standard_False;
3032 Handle(SALOME_InteractiveObject) anIO;
3033 if ( myUpdateColorScale )
3034 anIO = myApp->selectionMgr()->soleSelectedObject();
3036 if( !anIO.IsNull() )
3038 SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( aViewModel->CreatePrs( anIO->getEntry() ) );
3041 AIS_ListOfInteractive aList;
3042 aPrs->GetObjects( aList );
3043 AIS_ListIteratorOfListOfInteractive anIter( aList );
3044 for( ; anIter.More(); anIter.Next() )
3046 Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() );
3047 if( !aShape.IsNull() )
3049 GEOM::field_data_type aFieldDataType;
3050 int aFieldDimension;
3051 QList<QVariant> aFieldStepData;
3052 TCollection_AsciiString aFieldStepName;
3053 double aFieldStepRangeMin, aFieldStepRangeMax;
3054 aShape->getFieldStepInfo( aFieldDataType,
3059 aFieldStepRangeMax );
3060 if( !aFieldStepData.isEmpty() && aFieldDataType != GEOM::FDT_String )
3062 anIsDisplayColorScale = Standard_True;
3063 aColorScaleTitle = aFieldStepName;
3064 aColorScaleMin = aFieldStepRangeMin;
3065 aColorScaleMax = aFieldStepRangeMax;
3066 anIsBoolean = aFieldDataType == GEOM::FDT_Bool;
3073 if( anIsDisplayColorScale )
3075 SUIT_Session* session = SUIT_Session::session();
3076 SUIT_ResourceMgr* resMgr = session->resourceMgr();
3078 Standard_Real anXPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
3079 Standard_Real anYPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
3080 Standard_Real aWidth = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
3081 Standard_Real aHeight = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
3082 Standard_Integer aTextHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
3083 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
3085 #if OCC_VERSION_MAJOR < 7
3086 Handle(Aspect_ColorScale) myColorScale = aView->ColorScale();
3087 if( !myColorScale.IsNull() )
3089 myColorScale->SetXPosition( anXPos );
3090 myColorScale->SetYPosition( anYPos );
3091 myColorScale->SetWidth( aWidth );
3092 myColorScale->SetHeight( aHeight );
3094 Standard_Integer aWinWidth = 0, aWinHeight = 0;
3095 aView->Window()->Size (aWinWidth, aWinHeight);
3097 myColorScale->SetPosition (aWinWidth*anXPos, aWinHeight*anYPos);
3098 //myColorScale->SetBreadth (aWinWidth); // ???
3099 myColorScale->SetBreadth (aWinWidth*aWidth); // ???
3100 myColorScale->SetHeight (aWinHeight*aHeight);
3103 myColorScale->SetRange( aColorScaleMin, aColorScaleMax );
3104 myColorScale->SetNumberOfIntervals( anIsBoolean ? 2 : aNbIntervals );
3106 myColorScale->SetTextHeight( aTextHeight );
3107 myColorScale->SetTitle( aColorScaleTitle );
3109 #if OCC_VERSION_MAJOR < 7
3111 if( !aView->ColorScaleIsDisplayed() )
3112 aView->ColorScaleDisplay();
3115 if( aView->ColorScaleIsDisplayed() )
3116 aView->ColorScaleErase();
3118 if( !aViewModel->getAISContext()->IsDisplayed( myColorScale ) )
3119 aViewModel->getAISContext()->Display( myColorScale, Standard_True);
3122 if( aViewModel->getAISContext()->IsDisplayed( myColorScale ) )
3123 aViewModel->getAISContext()->Erase( myColorScale, Standard_True );
3126 if( theIsRedisplayFieldSteps )
3128 _PTR(Study) aStudyDS = getStudy()->studyDS();
3129 QList<SUIT_ViewManager*> vmList;
3130 myApp->viewManagers( vmList );
3131 for( QList<SUIT_ViewManager*>::Iterator vmIt = vmList.begin(); vmIt != vmList.end(); vmIt++ )
3133 if( SUIT_ViewManager* aViewManager = *vmIt )
3135 const ObjMap& anObjects = getStudy()->getObjectProperties( aViewManager->getGlobalId() );
3136 for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ )
3138 _PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) );
3141 CORBA::Object_var anObject = GeometryGUI::ClientSObjectToObject( aSObj );
3142 if( !CORBA::is_nil( anObject ) )
3144 GEOM::GEOM_FieldStep_var aFieldStep = GEOM::GEOM_FieldStep::_narrow( anObject );
3145 if( !aFieldStep->_is_nil() )
3147 CORBA::String_var aStepEntry = aFieldStep->GetStudyEntry();
3148 Handle(SALOME_InteractiveObject) aStepIO =
3149 new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" );
3150 Redisplay( aStepIO, false, false );