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( SalomeApp_Study* st )
467 : myIsRedisplayed( false )
470 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
475 SUIT_Session* session = SUIT_Session::session();
476 SUIT_ResourceMgr* resMgr = session->resourceMgr();
478 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
479 myShadingColor = SalomeApp_Tools::color( col );
481 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
482 myHasDisplayMode = false;
484 int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
486 myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
487 myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
488 myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
490 // Next properties provide a way to customize displaying of presentations;
491 // for instance, this is useful for preview
501 // This parameter is used for activisation/deactivisation (selection) of objects to be displayed
504 // Activate parallel vizualisation by default.
505 // It can be switched OFF via the environment variable:
506 // export PARALLEL_VISU=0
507 Standard_Boolean parallel_visu = Standard_True;
508 char* parallel_visu_env = getenv("PARALLEL_VISU");
509 if (parallel_visu_env && atoi(parallel_visu_env) == 0)
510 parallel_visu = Standard_False;
511 BRepMesh_IncrementalMesh::SetParallelDefault(parallel_visu);
515 #if OCC_VERSION_MAJOR >= 7
516 myColorScale = new AIS_ColorScale;
517 myColorScale->SetZLayer (Graphic3d_ZLayerId_TopOSD);
518 myColorScale->SetTransformPersistence (
519 Graphic3d_TransformPers::FromDeprecatedParams(Graphic3d_TMF_2d, gp_Pnt (-1,-1,0)));
522 myFieldDataType = GEOM::FDT_Double;
523 myFieldDimension = 0;
524 myFieldStepRangeMin = 0;
525 myFieldStepRangeMax = 0;
528 //=================================================================
530 * GEOM_Displayer::~GEOM_Displayer
533 //=================================================================
534 GEOM_Displayer::~GEOM_Displayer()
538 //=================================================================
540 * GEOM_Displayer::Display
541 * Display interactive object in the current viewer
543 //=================================================================
544 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
545 const bool updateViewer,
546 SALOME_View* theViewFrame )
548 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
551 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
555 vf->BeforeDisplay( this, prs );
556 vf->Display( this, prs );
557 vf->AfterDisplay( this, prs );
562 delete prs; // delete presentation because displayer is its owner
567 //=================================================================
569 * GEOM_Displayer::Display
570 * This overloaded Display() method can be useful for operations
571 * not using dialog boxes.
573 //=================================================================
574 void GEOM_Displayer::Display( GEOM::GEOM_BaseObject_ptr theObj, const bool updateViewer )
576 if ( theObj->_is_nil() )
579 std::string entry = getEntry( theObj );
581 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
586 //=================================================================
588 * GEOM_Displayer::Erase
589 * Erase interactive object in the current viewer
591 //=================================================================
592 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
594 const bool updateViewer,
595 SALOME_View* theViewFrame )
597 if ( theIO.IsNull() )
600 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
603 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
605 vf->BeforeErase( this, prs );
606 vf->Erase( this, prs, forced );
607 vf->AfterErase( this, prs );
610 delete prs; // delete presentation because displayer is its owner
615 //=================================================================
617 * GEOM_Displayer::Erase
618 * Erase geometry object in the current viewer
620 //=================================================================
621 void GEOM_Displayer::Erase( GEOM::GEOM_BaseObject_ptr theObj,
623 const bool updateViewer,
624 SALOME_View* theViewFrame)
626 std::string entry = getEntry( theObj );
629 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
630 forced, updateViewer, theViewFrame);
634 //=================================================================
636 * GEOM_Displayer::Redisplay
637 * Redisplay (erase and then display again) interactive object
638 * in the current viewer
640 //=================================================================
641 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
642 const bool updateViewer,
643 const bool checkActiveViewer )
645 bool aRedisplayed = myIsRedisplayed;
646 myIsRedisplayed = true;
647 // Remove the object permanently (<forced> == true)
648 SUIT_Session* ses = SUIT_Session::session();
649 SUIT_Application* app = ses->activeApplication();
652 SUIT_Desktop* desk = app->desktop();
653 QList<SUIT_ViewWindow*> wnds = desk->windows();
654 SUIT_ViewWindow* wnd;
655 QListIterator<SUIT_ViewWindow*> it( wnds );
656 while ( it.hasNext() && (wnd = it.next()) )
658 SUIT_ViewManager* vman = wnd->getViewManager();
661 SUIT_ViewModel* vmodel = vman->getViewModel();
664 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
667 if ( view->isVisible( theIO ) || ( checkActiveViewer && view == GetActiveView() ) )
669 Redisplay( theIO, updateViewer, view );
676 myIsRedisplayed = aRedisplayed;
679 //=================================================================
681 * GEOM_Displayer::Redisplay
682 * Redisplay (erase and then display again) interactive object
683 * in the specified view
685 //=================================================================
686 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
687 const bool theUpdateViewer,
688 SALOME_View* theViewFrame )
690 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
696 bool aRedisplayed = myIsRedisplayed;
697 myIsRedisplayed = true;
698 Erase( theIO, true, false, theViewFrame );
699 Display( theIO, theUpdateViewer, theViewFrame );
700 myIsRedisplayed = aRedisplayed;
701 // hide annotations for erased presentation
702 SUIT_Session* session = SUIT_Session::session();
703 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
704 GeometryGUI* aModule = dynamic_cast<GeometryGUI*>( anApp->activeModule() );
706 if ( !theViewFrame->isVisible( theIO ) ) {
707 aModule->GetAnnotationMgr()->EraseVisibleAnnotations(QString(theIO->getEntry()), dynamic_cast<SOCC_Viewer*>( theViewFrame ));
710 aModule->GetAnnotationMgr()->DisplayVisibleAnnotations(QString(theIO->getEntry()), dynamic_cast<SOCC_Viewer*>( theViewFrame ));
715 //=================================================================
717 * GEOM_Displayer::Display
718 * Calls Display() method for each object in the given list
720 //=================================================================
721 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
723 SALOME_ListIteratorOfListIO Iter( theIOList );
724 for ( ; Iter.More(); Iter.Next() ) {
725 Display( Iter.Value(), false );
731 void GEOM_Displayer::UpdateVisibility( SALOME_View* v, const SALOME_Prs* p, bool on )
733 SalomeApp_Study* aStudy = getStudy();
735 if ( v ) vId = getViewManagerId( v );
738 QString entry = p->GetEntry();
739 if ( !entry.isEmpty() ) {
741 aStudy->setObjectProperty( vId, entry, GEOM::propertyName( GEOM::Visibility ), on );
742 setVisibilityState( entry, on ? Qtx::ShownState : Qtx::HiddenState );
747 aStudy->setObjectProperty( vId, GEOM::propertyName( GEOM::Visibility ), on );
752 Quantity_Color GEOM_Displayer::qColorFromResources( const QString& property, const QColor& defColor )
754 // VSR: this method can be improved in future:
755 // to improve performance, the default values from resource manager should be cached in the displayer
756 return SalomeApp_Tools::color( SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor ) );
759 QColor GEOM_Displayer::colorFromResources( const QString& property, const QColor& defColor )
761 // VSR: this method can be improved in future:
762 // to improve performance, the default values from resource manager should be cached in the displayer
763 return SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor );
766 void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShape, bool create )
768 // check that shape is not null
769 if ( AISShape.IsNull() ) return;
771 // check that study is active
772 SalomeApp_Study* study = getStudy();
773 if ( !study ) return;
775 if ( myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
776 !TopoDS_Iterator(myShape).More() )
777 return; // NPAL15983 (Bug when displaying empty groups)
779 // set interactive object
781 Handle( SALOME_InteractiveObject ) anIO;
783 if ( !myIO.IsNull() ) {
784 AISShape->setIO( myIO );
785 AISShape->SetOwner( myIO );
788 else if ( !myName.empty() ) {
789 // workaround to allow selection of temporary objects
790 static int tempId = 0;
791 anIO = new SALOME_InteractiveObject( QString( "TEMP_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
792 AISShape->setIO( anIO );
793 AISShape->SetOwner( anIO );
796 // flag: only vertex or compound of vertices is processed (specific handling)
797 bool onlyVertex = myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape );
798 // presentation study entry (empty for temporary objects like preview)
799 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
800 // flag: temporary object
801 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
802 // currently active view window's ID (-1 if no active view)
803 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
805 // get presentation properties
806 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
808 // Temporary staff: vertex must be infinite for correct visualization
809 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
812 Material_Model material;
813 // if predefined color isn't set in displayer(via GEOM_Displayer::SetColor() function)
815 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
816 // - set front material properties
817 AISShape->SetCurrentFacingModel( Aspect_TOFM_FRONT_SIDE );
818 AISShape->SetMaterial( material.getMaterialOCCAspect( true ) );
819 // - set back material properties
820 AISShape->SetCurrentFacingModel( Aspect_TOFM_BACK_SIDE );
821 AISShape->SetMaterial( material.getMaterialOCCAspect( false ) );
822 // - switch to default (both sides) facing mode
823 AISShape->SetCurrentFacingModel( Aspect_TOFM_BOTH_SIDE );
829 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function;
830 // we set it to the shape not taking into account material properties
831 AISShape->SetShadingColor( (Quantity_NameOfColor)GetColor() );
833 else if ( !material.isPhysical() ) {
834 // shading color from properties is used only for non-physical materials
835 AISShape->SetShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>() ) );
839 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
840 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
841 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
842 AISShape->Attributes()->SetLineAspect( anAspect );
844 // - unfree boundaries color
845 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
846 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
847 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
848 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
850 // - free boundaries color
851 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
852 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
853 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>() ) );
854 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
856 // - standalone edges color
857 anAspect = AISShape->Attributes()->WireAspect();
858 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
859 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>() ) );
860 AISShape->Attributes()->SetWireAspect( anAspect );
862 // - color for edges in shading+edges mode
863 AISShape->SetEdgesInShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
865 // - color of labels (textual fields and shape name)
866 AISShape->SetLabelColor( qColorFromResources( "label_color", QColor( 255, 255, 255 ) ) );
869 AISShape->SetDisplayMode( HasDisplayMode() ?
870 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
872 // display mode from properties
873 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt() );
875 // - face boundaries color and line width
876 anAspect = AISShape->Attributes()->FaceBoundaryAspect();
877 anAspect->SetColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
878 anAspect->SetWidth( HasWidth() ? GetWidth() : propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
879 AISShape->Attributes()->SetFaceBoundaryAspect( anAspect );
881 // set display vectors flag
882 AISShape->SetDisplayVectors( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
884 // set display vertices flag
885 bool isVerticesMode = propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool();
886 AISShape->SetDisplayVertices( isVerticesMode );
888 // set display name flag
889 bool isNameMode = propMap.value( GEOM::propertyName( GEOM::ShowName ) ).toBool();
890 AISShape->SetDisplayName( isNameMode );
893 if( HasTransparency() ) {
894 AISShape->SetTransparency( GetTransparency() );
896 AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
899 // set iso properties
900 int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt();
901 int vIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[1].toInt();
902 Quantity_Color isosColor = SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>() );
903 int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt();
904 Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect();
905 Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect();
907 if ( HasIsosColor() ) {
908 uIsoAspect->SetColor( (Quantity_NameOfColor)GetIsosColor() );
909 vIsoAspect->SetColor( (Quantity_NameOfColor)GetIsosColor() );
912 uIsoAspect->SetColor( isosColor );
913 vIsoAspect->SetColor( isosColor );
916 if ( HasIsosWidth() ) {
917 uIsoAspect->SetWidth( GetIsosWidth() );
918 vIsoAspect->SetWidth( GetIsosWidth() );
921 uIsoAspect->SetWidth( isosWidth );
922 vIsoAspect->SetWidth( isosWidth );
926 uIsoAspect->SetNumber( GetNbIsos() );
927 vIsoAspect->SetNumber( GetNbIsos() );
930 uIsoAspect->SetNumber( uIsos );
931 vIsoAspect->SetNumber( vIsos );
934 AISShape->Attributes()->SetUIsoAspect( uIsoAspect );
935 AISShape->Attributes()->SetVIsoAspect( vIsoAspect );
937 // set deflection coefficient
938 // ... to avoid to small values of the coefficient, its lower value is limited
939 AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) );
943 if ( HasTexture() ) {
944 // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function
945 aImagePath = GetTexture().c_str();
946 if ( ! entry.isEmpty() ) {
947 // check that study is active
948 SalomeApp_Study* study = getActiveStudy();
950 // Store the texture in object properties for next displays
951 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) );
952 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
954 // Update propeties map
955 propMap = getObjectProperties( study, entry, myViewFrame );
960 aImagePath = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
963 #ifdef USE_TEXTURED_SHAPE
964 Handle(Image_PixMap) aPixmap;
965 if ( !aImagePath.isEmpty() )
966 aPixmap = cacheTextureFor( aImagePath, AISShape );
968 aPixmap = getDefaultTexture();
970 // apply image to shape
971 if ( !aPixmap.IsNull() ) {
972 AISShape->SetTexturePixMap( aPixmap );
973 AISShape->SetTextureMapOn();
974 AISShape->DisableTextureModulate();
977 AISShape->SetTextureMapOff();
982 AISShape->SetWidth( HasWidth() ?
983 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
985 // libe width from properties
986 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
988 // set top-level flag
989 AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
991 // set point marker (for vertex / compound of vertices only)
992 if ( onlyVertex || isVerticesMode ) {
993 QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
994 if ( aList.size() == 2 ) {
995 // standard marker string contains "TypeOfMarker:ScaleOfMarker"
996 int aTypeOfMarker = aList[0].toInt();
997 double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
998 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
999 anAspect->SetScale( aScaleOfMarker );
1000 anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
1001 anAspect->SetColor( HasColor() ?
1002 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1003 (Quantity_NameOfColor)GetColor() :
1004 // color from properties
1005 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ) );
1006 AISShape->Attributes()->SetPointAspect( anAspect );
1008 else if ( aList.size() == 1 ) {
1009 // custom marker string contains "IdOfTexture"
1010 int textureId = aList[0].toInt();
1011 Standard_Integer aWidth, aHeight;
1012 Handle(TColStd_HArray1OfByte) aTexture =
1013 GeometryGUI::getTexture( study, textureId, aWidth, aHeight );
1014 if ( !aTexture.IsNull() ) {
1015 Handle(Prs3d_PointAspect) aTextureAspect =
1016 new Prs3d_PointAspect( HasColor() ?
1017 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1018 (Quantity_NameOfColor)GetColor() :
1019 // color from properties
1020 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
1023 AISShape->Attributes()->SetPointAspect( aTextureAspect );
1028 // set field step data
1029 AISShape->setFieldStepInfo( myFieldDataType,
1033 myFieldStepRangeMin,
1034 myFieldStepRangeMax );
1036 if ( create && !isTemporary && aMgrId != -1 ) {
1037 // set properties to the study
1038 study->setObjectProperties( aMgrId, entry, propMap );
1041 // AISShape->SetName(???); ??? necessary to set name ???
1044 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
1046 // check that actor is not null
1047 if ( !actor ) return;
1049 // check that study is active
1050 SalomeApp_Study* study = getStudy();
1051 if ( !study ) return;
1053 // set interactive object
1055 Handle( SALOME_InteractiveObject ) anIO;
1057 if ( !myIO.IsNull() ) {
1058 actor->setIO( myIO );
1061 else if ( !myName.empty() ) {
1062 // workaround to allow selection of temporary objects
1063 static int tempId = 0;
1064 anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
1065 actor->setIO( anIO );
1068 // presentation study entry (empty for temporary objects like preview)
1069 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
1070 // flag: temporary object
1071 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
1072 // currently active view window's ID (-1 if no active view)
1073 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
1075 // get presentation properties
1076 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
1079 /////////////////////////////////////////////////////////////////////////
1080 // VSR: for VTK viewer currently deflection coefficient is hardcoded
1081 // due to performance problem
1082 // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
1083 /////////////////////////////////////////////////////////////////////////
1084 if ( !actor->getTopo().IsSame( myShape ) )
1085 #ifdef LIMIT_DEFLECTION_FOR_VTK
1086 actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
1088 actor->SetShape( myShape, qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ), myType == GEOM_VECTOR );
1092 Material_Model material;
1093 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
1094 std::vector<vtkProperty*> mprops;
1095 mprops.push_back( material.getMaterialVTKProperty( true ) );
1096 mprops.push_back( material.getMaterialVTKProperty( false) );
1097 actor->SetMaterial( mprops );
1099 // set iso-lines properties
1101 // - set number of iso-lines
1102 int nbIsos[2]= { 1, 1 };
1103 if ( HasNbIsos() ) {
1104 nbIsos[0] = GetNbIsos();
1105 nbIsos[1] = GetNbIsos();
1108 QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
1109 nbIsos[0] = isos[0].toInt();
1110 nbIsos[1] = isos[1].toInt();
1112 actor->SetNbIsos( nbIsos );
1114 // - set iso-lines width
1115 actor->SetIsosWidth( HasIsosWidth() ? GetIsosWidth() : propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
1117 // - set iso-lines color
1118 if ( HasIsosColor() )
1119 c = SalomeApp_Tools::color( Quantity_Color((Quantity_NameOfColor)GetIsosColor()) );
1121 c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
1122 actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
1127 // - same color for all sub-actors
1128 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1129 actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1132 // shading color (for non-physical materials)
1133 if ( !material.isPhysical() ) {
1134 c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
1135 actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1136 actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1139 // - standalone edge color
1140 c = propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>();
1141 actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1143 c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
1144 // - shared edges color ???
1145 actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1147 c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
1148 // - free edges color ???
1149 actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
1152 c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
1153 actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
1156 // - color for edges in shading+edges mode
1157 c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
1158 actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
1160 // - color of labels (shape name)
1161 c = colorFromResources( "label_color", QColor( 255, 255, 255 ) );
1162 actor->SetLabelColor( c.redF(), c.greenF(), c.blueF() );
1165 if( HasTransparency() ) {
1166 actor->SetOpacity( 1.0 - GetTransparency() );
1168 actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
1172 actor->SetWidth( HasWidth() ?
1173 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1175 // libe width from properties
1176 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
1178 // set display vectors flag
1179 actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
1181 // set display vertices flag
1182 actor->SetVerticesMode( propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool() );
1184 // set display name flag
1185 actor->SetNameMode( propMap.value( GEOM::propertyName( GEOM::ShowName ) ).toBool() );
1188 int displayMode = HasDisplayMode() ?
1189 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
1191 // display mode from properties
1192 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
1194 // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
1195 // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
1196 // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
1197 // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
1199 if ( displayMode == 2 )
1200 // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
1201 // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
1203 actor->setDisplayMode( displayMode );
1206 actor->PickableOn();
1208 actor->PickableOff();
1210 if ( create && !isTemporary && aMgrId != -1 ) {
1211 // set properties to the study
1212 study->setObjectProperties( aMgrId, entry, propMap );
1216 //=================================================================
1218 * GEOM_Displayer::updateDimensions
1219 * Creates or renews dimension presentation for the IO.
1221 //=================================================================
1222 void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& theIO,
1223 SALOME_OCCPrs* thePrs,
1224 const gp_Ax3& theShapeLCS )
1226 SalomeApp_Study* aStudy = getStudy();
1232 if ( theIO.IsNull() )
1237 SOCC_Prs* anOccPrs = dynamic_cast<SOCC_Prs*>( thePrs );
1239 AIS_ListOfInteractive aListOfIO;
1241 anOccPrs->GetObjects( aListOfIO );
1243 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
1245 // remove outdated presentations of dimensions
1246 for ( ; aIterateIO.More(); aIterateIO.Next() )
1248 const Handle(AIS_InteractiveObject)& anIO = aIterateIO.Value();
1249 if ( !anIO->IsKind( STANDARD_TYPE( AIS_Dimension ) ) )
1254 aListOfIO.Remove( aIterateIO );
1256 if ( !aIterateIO.More() )
1262 // prepare dimension styling
1263 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1265 QColor aQColor = aResMgr->colorValue ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
1266 int aLineWidth = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
1267 QFont aFont = aResMgr->fontValue ( "Geometry", "dimensions_font", QFont("Y14.5M-2009", 14) );
1268 double anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
1269 bool isUnitsShown = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
1270 QString aUnitsLength = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
1271 QString aUnitsAngle = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
1272 bool aUseText3d = aResMgr->booleanValue( "Geometry", "dimensions_use_text3d", false );
1274 // restore dimension presentation from saved attribute or property data
1275 AIS_ListOfInteractive aRestoredDimensions;
1277 QVariant aProperty = aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1279 GEOM::propertyName( GEOM::Dimensions ),
1282 GEOMGUI_DimensionProperty aRecords;
1284 if ( aProperty.isValid() && aProperty.canConvert<GEOMGUI_DimensionProperty>() )
1286 aRecords = aProperty.value<GEOMGUI_DimensionProperty>();
1290 aRecords.LoadFromAttribute( getStudy(), theIO->getEntry() );
1293 // create up-to-date dimension presentations
1294 for ( int aPrsIt = 0; aPrsIt < aRecords.GetNumber(); ++aPrsIt )
1296 if ( !aRecords.IsVisible( aPrsIt ) )
1301 // init dimension by type
1302 Handle(AIS_Dimension) aPrs;
1303 switch( aRecords.GetType( aPrsIt ) )
1305 case GEOMGUI_DimensionProperty::DimensionType_Length :
1307 Handle(GEOM_AISLength) aLength = new GEOM_AISLength( aPrsIt );
1308 aRecords.GetRecord( aPrsIt )->AsLength()->Update( aLength, theShapeLCS );
1313 case GEOMGUI_DimensionProperty::DimensionType_Diameter :
1315 Handle(GEOM_AISDiameter) aDiam = new GEOM_AISDiameter( aPrsIt );
1316 aRecords.GetRecord( aPrsIt )->AsDiameter()->Update( aDiam, theShapeLCS );
1321 case GEOMGUI_DimensionProperty::DimensionType_Angle :
1323 Handle(GEOM_AISAngle) anAng = new GEOM_AISAngle( aPrsIt );
1324 aRecords.GetRecord( aPrsIt )->AsAngle()->Update( anAng, theShapeLCS );
1330 aPrs->SetOwner( theIO );
1332 Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
1334 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
1336 aStyle->SetCommonColor( aColor );
1337 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1338 aStyle->MakeText3d( aUseText3d );
1339 aStyle->MakeTextShaded( Standard_True );
1340 int fsize = aFont.pixelSize() != -1 ? aFont.pixelSize() : aFont.pointSize();
1341 aStyle->SetExtensionSize( fsize * 0.5 );
1342 aStyle->TextAspect()->SetFont( aFont.family().toLatin1().data() );
1343 aStyle->TextAspect()->SetHeight( fsize );
1344 aStyle->ArrowAspect()->SetLength( anArrowLength );
1345 aStyle->LineAspect()->SetWidth( aLineWidth );
1346 aStyle->SetTextHorizontalPosition( aPrs->DimensionAspect()->TextHorizontalPosition() );
1347 aStyle->SetTextVerticalPosition( aPrs->DimensionAspect()->TextVerticalPosition() );
1348 aStyle->SetArrowOrientation( aPrs->DimensionAspect()->ArrowOrientation() );
1349 aPrs->SetDimensionAspect( aStyle );
1350 aPrs->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
1351 aPrs->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
1352 aPrs->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
1354 if ( aPrs->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
1356 // show degree symbol for dimension instead of label "deg"
1357 if ( aUnitsAngle == "deg" )
1359 aPrs->SetSpecialSymbol(0xB0);
1360 aPrs->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
1361 aStyle->MakeUnitsDisplayed(Standard_False);
1365 aPrs->SetDisplaySpecialSymbol(AIS_DSS_No);
1366 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1371 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1374 aListOfIO.Append( aPrs );
1377 // update presentation
1380 for ( aIterateIO.Initialize( aListOfIO ); aIterateIO.More(); aIterateIO.Next() )
1382 anOccPrs->AddObject( aIterateIO.Value() );
1386 //=================================================================
1388 * GEOM_Displayer::Erase
1389 * Calls Erase() method for each object in the given list
1391 //=================================================================
1392 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
1394 const bool updateViewer )
1396 SALOME_ListIteratorOfListIO Iter( theIOList );
1397 for ( ; Iter.More(); Iter.Next() )
1398 Erase( Iter.Value(), forced, false );
1404 //=================================================================
1406 * GEOM_Displayer::Redisplay
1407 * Calls Redisplay() method for each object in the given list
1409 //=================================================================
1410 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1411 const bool updateViewer,
1412 const bool checkActiveViewer )
1414 SALOME_ListIteratorOfListIO Iter( theIOList );
1415 for ( ; Iter.More(); Iter.Next() )
1416 Redisplay( Iter.Value(), false, checkActiveViewer );
1422 //=================================================================
1424 * GEOM_Displayer::Redisplay
1425 * Calls Redisplay() method for each object in the given list
1427 //=================================================================
1428 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1429 const bool theUpdateViewer,
1430 SALOME_View* theViewFrame )
1432 SALOME_ListIteratorOfListIO anIter( theIOList );
1433 for ( ; anIter.More(); anIter.Next() )
1435 Redisplay( anIter.Value(), false, theViewFrame );
1438 if ( theUpdateViewer )
1444 //=================================================================
1446 * GEOM_Displayer::Update
1447 * Update OCC presentaion
1448 * [ Reimplemented from SALOME_Displayer ]
1450 //=================================================================
1451 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
1453 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
1454 SalomeApp_Study* study = getStudy();
1456 if ( !occPrs || myShape.IsNull() || !study )
1459 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1462 // specific processing for local coordinate system presentation
1465 TopoDS_Face aFace = TopoDS::Face( myShape );
1466 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1467 if ( !aPlane.IsNull() )
1469 gp_Ax3 aPos = aPlane->Pln().Position();
1470 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1472 Handle(GEOM_AISTrihedron) aTrh;
1474 if ( occPrs->IsNull() )
1476 // new presentation is being created
1477 aTrh = new GEOM_AISTrihedron( aPlc );
1478 occPrs->AddObject( aTrh );
1482 // presentation is being updated
1483 AIS_ListOfInteractive aList;
1484 occPrs->GetObjects( aList );
1485 AIS_ListIteratorOfListOfInteractive anIter( aList );
1486 for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
1487 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
1491 if ( !aTrh.IsNull() ) {
1492 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1494 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1495 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1497 aTrh->SetWidth( GetWidth() );
1499 if ( !myIO.IsNull() )
1501 aTrh->setIO( myIO );
1502 aTrh->SetOwner( myIO );
1504 aTrh->SetComponent( aPlc );
1505 aTrh->SetToUpdate();
1507 occPrs->SetToActivate( ToActivate() );
1513 // processing for usual geometry presentation
1516 // if presentation is empty we try to create new one
1517 if ( occPrs->IsNull() )
1519 // create presentation (specific for vectors)
1520 Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1521 : new GEOM_AISShape ( myShape, "" );
1523 if( myType == GEOM_FIELD_STEP )
1524 AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight );
1525 // update shape properties
1526 updateShapeProperties( AISShape, true );
1528 // add shape to the presentation
1529 occPrs->AddObject( AISShape );
1531 // In accordance with ToActivate() value object will be activated/deactivated
1532 // when it will be displayed
1533 occPrs->SetToActivate( ToActivate() );
1535 if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1536 // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1538 // create additional wireframe shape
1539 Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1540 aWirePrs->SetWidth(AISShape->Width());
1541 if ( !myIO.IsNull() ) {
1542 aWirePrs->setIO( myIO );
1543 aWirePrs->SetOwner( myIO );
1546 // add shape to the presentation
1547 occPrs->AddObject( aWirePrs );
1550 // if presentation is found -> set again shape for it
1553 AIS_ListOfInteractive IOList;
1554 occPrs->GetObjects( IOList );
1555 AIS_ListIteratorOfListOfInteractive Iter( IOList );
1556 for ( ; Iter.More(); Iter.Next() )
1558 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1559 if ( AISShape.IsNull() )
1562 // re-set shape (it might be changed)
1563 if ( AISShape->Shape() != myShape )
1564 AISShape->Set( myShape );
1566 // update shape properties
1567 updateShapeProperties( AISShape, false );
1570 AISShape->UpdateSelection();
1571 AISShape->SetToUpdate();
1575 updateDimensions( myIO, occPrs, gp_Ax3().Transformed( myShape.Location().Transformation() ) );
1579 //=================================================================
1581 * GEOM_Displayer::Update
1582 * Update VTK presentaion
1583 * [ Reimplemented from SALOME_Displayer ]
1585 //=================================================================
1586 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1588 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1589 SalomeApp_Study* study = getStudy();
1591 if ( !vtkPrs || myShape.IsNull() || !study )
1594 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1597 // specific processing for local coordinate system presentation
1600 TopoDS_Face aFace = TopoDS::Face( myShape );
1601 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1602 if ( !aPlane.IsNull() ) {
1603 gp_Ax3 aPos = aPlane->Pln().Position();
1604 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1606 GEOM_VTKTrihedron* aTrh = 0;
1608 if ( vtkPrs->IsNull() ) {
1609 // new presentation is being created
1610 aTrh = GEOM_VTKTrihedron::New();
1611 vtkPrs->AddObject( aTrh );
1614 // presentation is being updated
1615 vtkActorCollection* actors = vtkPrs->GetObjects();
1617 actors->InitTraversal();
1618 vtkActor* a = actors->GetNextActor();
1619 while ( a && !aTrh ) {
1620 aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1621 a = actors->GetNextActor();
1627 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1629 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1630 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1632 #ifdef VTK_TRIHEDRON_WIDTH
1634 // VSR: currently isn't supported
1636 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1638 aTrh->SetWidth( GetWidth() );
1641 if ( !myIO.IsNull() )
1642 aTrh->setIO( myIO );
1644 aTrh->SetPlacement( aPlc );
1651 // processing for usual geometry presentation
1654 // if presentation is empty we try to create new one
1655 if ( vtkPrs->IsNull() )
1658 GEOM_Actor* actor = GEOM_Actor::New();
1659 // update actor properties
1660 updateActorProperties( actor, true );
1661 // add actor to the presentation
1662 vtkPrs->AddObject( actor );
1665 // presentation is being updated
1666 vtkActorCollection* actors = vtkPrs->GetObjects();
1668 actors->InitTraversal();
1669 vtkActor* a = actors->GetNextActor();
1671 GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1673 // update actor properties
1674 updateActorProperties( actor, false );
1675 a = actors->GetNextActor();
1683 //=================================================================
1685 * GEOM_Displayer::BuildPrs
1686 * Build presentation accordint to the current viewer type
1688 //=================================================================
1689 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1691 if ( theObj->_is_nil() )
1694 myViewFrame = GetActiveView();
1695 if ( myViewFrame == 0 )
1698 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1703 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1704 myType = theObj->GetType();
1706 // Update presentation
1712 //=================================================================
1714 * GEOM_Displayer::BuildPrs
1715 * Build presentation accordint to the current viewer type
1717 //=================================================================
1718 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1720 myViewFrame = GetActiveView();
1721 if ( theShape.IsNull() || myViewFrame == 0 )
1724 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1729 setShape( theShape );
1737 //=================================================================
1739 * GEOM_Displayer::buildPresentation
1740 * Builds/finds object's presentation for the current viewer
1741 * Calls corresponding Update() method by means of double dispatch
1744 //=================================================================
1745 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1746 SALOME_View* theViewFrame )
1748 SALOME_Prs* prs = 0;
1751 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1755 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1758 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1759 theIO->setEntry( entry.toLatin1().constData() );
1760 if ( !theIO.IsNull() )
1762 // set interactive object
1764 // Find SOBject (because shape should be published previously)
1765 SUIT_Session* session = SUIT_Session::session();
1766 SUIT_Application* app = session->activeApplication();
1769 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1772 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1775 // get CORBA reference to data object
1776 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1777 if ( !CORBA::is_nil( object ) )
1779 // downcast to GEOM base object
1780 GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
1781 if ( !GeomBaseObject->_is_nil() )
1783 myType = GeomBaseObject->GetType();
1785 // downcast to GEOM object
1786 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
1787 if ( myType == GEOM_FIELD_STEP )
1789 // get the GEOM object from the field's shape
1790 GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
1791 if ( !GeomFieldStep->_is_nil() )
1793 GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
1794 if ( !GeomField->_is_nil() )
1795 GeomObject = GeomField->GetShape();
1798 // read the field step information
1799 readFieldStepInfo( GeomFieldStep );
1802 if ( !GeomObject->_is_nil() )
1804 theIO->setName( GeomObject->GetName() );
1805 // finally set shape
1806 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1814 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1820 //=================================================================
1822 * GEOM_Displayer::buildSubshapePresentation
1823 * Builds/finds object's presentation for the current viewer
1824 * Calls corresponding Update() method by means of double dispatch
1825 * For not published objects (for Mantis issue 0020435)
1827 //=================================================================
1828 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1829 const QString& entry,
1830 SALOME_View* theViewFrame)
1832 SALOME_Prs* prs = 0;
1835 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1839 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1842 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1843 theIO->setEntry(entry.toLatin1().constData());
1844 if (!theIO.IsNull())
1846 // set interactive object
1848 // finally set shape
1850 myType = GEOM_SUBSHAPE;
1852 UpdatePrs(prs); // Update presentation by using of the double dispatch
1858 //=================================================================
1860 * GEOM_Displayer::internalReset
1861 * Resets internal data
1864 //=================================================================
1865 void GEOM_Displayer::internalReset()
1870 myFieldDataType = GEOM::FDT_Double;
1871 myFieldDimension = 0;
1872 myFieldStepData.clear();
1873 myFieldStepName.Clear();
1874 myFieldStepRangeMin = 0;
1875 myFieldStepRangeMax = 0;
1878 //=================================================================
1880 * GEOM_Displayer::LocalSelection
1881 * Activate selection of CAD shapes with activisation of selection
1882 * of their sub-shapes (with opened local context for OCC viewer)
1884 //=================================================================
1885 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const std::list<int> modes )
1887 SUIT_Session* session = SUIT_Session::session();
1888 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1892 LightApp_SelectionMgr* sm = app->selectionMgr();
1894 // remove all filters from selection
1897 SALOME_View* vf = GetActiveView();
1899 if (!theIO.IsNull() && !vf->isVisible(theIO))
1901 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1902 vf->LocalSelection( prs, modes );
1903 delete prs; // delete presentation because displayer is its owner
1907 //=================================================================
1909 * GEOM_Displayer::LocalSelection
1910 * Activate selection of CAD shapes with activisation of selection
1911 * of their sub-shapes (with opened local context for OCC viewer)
1913 //=================================================================
1914 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1916 std::list<int> modes;
1917 modes.push_back( theMode );
1918 LocalSelection( theIO, modes );
1921 //=================================================================
1923 * GEOM_Displayer::globalSelection
1924 * Activate selection of CAD shapes without activisation of selection
1925 * of their sub-shapes (without opened local context for OCC viewer)
1927 //=================================================================
1928 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1930 TColStd_MapOfInteger aModes;
1931 aModes.Add( theMode );
1932 GlobalSelection( aModes, update );
1935 //=================================================================
1937 * GEOM_Displayer::globalSelection
1938 * Activate selection of CAD shapes without activisation of selection
1939 * of their sub-shapes (without opened local context for OCC viewer)
1941 //=================================================================
1942 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1943 const bool update, const QList<int>* theSubShapes )
1945 SUIT_Session* session = SUIT_Session::session();
1946 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1950 SALOME_View* vf = GetActiveView();
1954 // Close local context
1955 vf->GlobalSelection( update );
1957 // Set selection filters in accordance with current mode
1958 LightApp_SelectionMgr* sm = app->selectionMgr();
1962 // Remove from selection temporary objects if necessary
1963 if ( !theModes.Contains( GEOM_PREVIEW ) )
1964 clearTemporary( sm );
1966 //@ aSel->ClearIndex();
1970 // Remove filters from AIS_InteractiveContext
1971 Handle(AIS_InteractiveContext) ic;
1972 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1975 ic = viewer->getAISContext();
1977 ic->RemoveFilters();
1980 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1983 SUIT_SelectionFilter* aFilter;
1984 if ( theModes.Extent() == 1 )
1986 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1988 if ( aMode == GEOM_COMPOUNDFILTER )
1989 aFilter = getComplexFilter( theSubShapes );
1991 aFilter = getFilter( aMode );
1993 else if ( theModes.Extent() > 1 )
1995 TColStd_MapOfInteger aTopAbsModes;
1996 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1997 QList<SUIT_SelectionFilter*> aListOfFilters;
1998 for ( ; anIter.More(); anIter.Next() )
2000 SUIT_SelectionFilter* aFilter;
2001 int aMode = anIter.Key();
2002 if ( aMode == GEOM_COMPOUNDFILTER )
2003 aFilter = getComplexFilter( theSubShapes );
2005 aFilter = getFilter( aMode );
2008 aListOfFilters.append( aFilter );
2011 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
2018 sm->installFilter( aFilter );
2021 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
2022 ic->AddFilter( anOCCFilter );
2027 //=================================================================
2029 * GEOM_Displayer::LocalSelection
2030 * Activate selection of CAD shapes with activisation of selection
2031 * of their sub-shapes (with opened local context for OCC viewer)
2033 //=================================================================
2034 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const std::list<int> modes )
2036 SALOME_ListIteratorOfListIO Iter( theIOList );
2037 for ( ; Iter.More(); Iter.Next() )
2038 LocalSelection( Iter.Value(), modes );
2041 //=================================================================
2043 * GEOM_Displayer::LocalSelection
2044 * Activate selection of CAD shapes with activisation of selection
2045 * of their sub-shapes (with opened local context for OCC viewer)
2047 //=================================================================
2048 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
2050 std::list<int> modes;
2051 modes.push_back( theMode );
2052 LocalSelection( theIOList, modes );
2055 //=================================================================
2057 * GEOM_Displayer::BeforeDisplay
2058 * Called before displaying of pars. Close local context
2059 * [ Reimplemented from SALOME_Displayer ]
2061 //=================================================================
2062 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
2064 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
2067 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
2070 if ( ic->HasOpenedContext() )
2071 ic->CloseAllContexts(Standard_True);
2076 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
2078 UpdateColorScale(false,false);
2080 // visualize annotations for displayed presentation
2081 SUIT_Session* session = SUIT_Session::session();
2082 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2083 GeometryGUI* aModule = dynamic_cast<GeometryGUI*>( anApp->activeModule() );
2085 if ( !myIsRedisplayed ) {
2086 aModule->GetAnnotationMgr()->DisplayVisibleAnnotations(QString(p->GetEntry()), dynamic_cast<SOCC_Viewer*>( v ));
2088 aModule->GetAnnotationMgr()->UpdateVisibleAnnotations(QString(p->GetEntry()), dynamic_cast<SOCC_Viewer*>( v ));
2093 void GEOM_Displayer::BeforeErase( SALOME_View* v, const SALOME_OCCPrs* p )
2095 LightApp_Displayer::BeforeErase( v, p );
2096 releaseTextures( p );
2099 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
2101 LightApp_Displayer::AfterErase( v, p );
2102 UpdateColorScale(false,false);
2104 if ( !myIsRedisplayed ) {
2105 // hide annotations for erased presentation
2106 SUIT_Session* session = SUIT_Session::session();
2107 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2108 GeometryGUI* aModule = dynamic_cast<GeometryGUI*>( anApp->activeModule() );
2110 aModule->GetAnnotationMgr()->EraseVisibleAnnotations(QString(p->GetEntry()), dynamic_cast<SOCC_Viewer*>( v ));
2114 //=================================================================
2116 * GEOM_Displayer::SetColor
2117 * Set color for shape displaying. If it is equal -1 then default color is used.
2118 * Available values are from Quantity_NameOfColor enumeration
2120 //=================================================================
2121 void GEOM_Displayer::SetColor( const int color )
2128 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
2132 int GEOM_Displayer::GetColor() const
2137 bool GEOM_Displayer::HasColor() const
2139 return myColor != -1;
2142 void GEOM_Displayer::UnsetColor()
2146 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2147 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
2148 myShadingColor = SalomeApp_Tools::color( col );
2151 //=================================================================
2153 * GEOM_Displayer::SetTransparency
2154 * Set transparency for shape displaying.
2156 //=================================================================
2157 double GEOM_Displayer::SetTransparency( const double transparency )
2159 double prevTransparency = myTransparency;
2160 myTransparency = transparency;
2161 return prevTransparency;
2164 //=================================================================
2166 * GEOM_Displayer::GetTransparency
2167 * Get transparency for shape displaying.
2169 //=================================================================
2170 double GEOM_Displayer::GetTransparency() const
2172 return myTransparency;
2175 //=================================================================
2177 * GEOM_Displayer::HasTransparency
2178 * Check if transparency for shape displaying is set.
2180 //=================================================================
2181 bool GEOM_Displayer::HasTransparency() const
2183 return myTransparency >= 0;
2186 //=================================================================
2188 * GEOM_Displayer::UnsetTransparency
2189 * Unset transparency for shape displaying.
2191 //=================================================================
2192 double GEOM_Displayer::UnsetTransparency()
2194 return SetTransparency( -1 );
2197 //=================================================================
2199 * GEOM_Displayer::SetTexture
2201 //=================================================================
2202 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
2204 myTexture = texureFileName;
2207 bool GEOM_Displayer::HasTexture() const
2209 return myTexture != "";
2212 std::string GEOM_Displayer::GetTexture() const
2217 //=================================================================
2219 * GEOM_Displayer::SetWidth
2220 * Set width of shape displaying. If it is equal -1 then default width is used.
2222 //=================================================================
2223 void GEOM_Displayer::SetWidth( const double width )
2228 double GEOM_Displayer::GetWidth() const
2233 bool GEOM_Displayer::HasWidth() const
2235 return myWidth != -1;
2238 void GEOM_Displayer::UnsetWidth()
2243 int GEOM_Displayer::GetIsosWidth() const
2248 void GEOM_Displayer::SetIsosWidth(const int width)
2250 myIsosWidth = width;
2253 bool GEOM_Displayer::HasIsosWidth() const
2255 return myIsosWidth != -1;
2258 int GEOM_Displayer::SetNbIsos( const int nbIsos )
2260 int prevNbIsos = myNbIsos;
2265 int GEOM_Displayer::UnsetNbIsos()
2267 return SetNbIsos( -1 );
2270 int GEOM_Displayer::GetNbIsos() const
2275 bool GEOM_Displayer::HasNbIsos() const
2277 return myNbIsos >= 0;
2280 int GEOM_Displayer::SetIsosColor( const int color )
2282 int prevColor = myIsosColor;
2283 myIsosColor = color;
2287 int GEOM_Displayer::GetIsosColor() const
2292 bool GEOM_Displayer::HasIsosColor() const
2294 return myIsosColor != -1;
2297 int GEOM_Displayer::UnsetIsosColor()
2299 return SetIsosColor( -1 );
2302 //=================================================================
2304 * GEOM_Displayer::SetToActivate
2305 * This method is used for activisation/deactivisation of objects to be displayed
2307 //=================================================================
2308 void GEOM_Displayer::SetToActivate( const bool toActivate )
2310 myToActivate = toActivate;
2312 bool GEOM_Displayer::ToActivate() const
2314 return myToActivate;
2317 //=================================================================
2319 * GEOM_Displayer::clearTemporary
2320 * Removes from selection temporary objects
2322 //=================================================================
2323 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
2325 SALOME_ListIO selected, toSelect;
2326 theSelMgr->selectedObjects( selected );
2328 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
2329 Handle(SALOME_InteractiveObject) io = it.Value();
2330 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
2331 toSelect.Append( it.Value() );
2334 theSelMgr->setSelectedObjects( toSelect, true );
2337 void GEOM_Displayer::SetName( const char* theName )
2342 void GEOM_Displayer::UnsetName()
2347 SalomeApp_Study* GEOM_Displayer::getStudy() const
2349 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2352 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
2357 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
2362 void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
2363 const int theFieldDimension,
2364 const QList<QVariant>& theFieldStepData,
2365 const TCollection_AsciiString& theFieldStepName,
2366 const double theFieldStepRangeMin,
2367 const double theFieldStepRangeMax )
2369 myFieldDataType = theFieldDataType;
2370 myFieldDimension = theFieldDimension;
2371 myFieldStepData = theFieldStepData;
2372 myFieldStepName = theFieldStepName;
2373 myFieldStepRangeMin = theFieldStepRangeMin;
2374 myFieldStepRangeMax = theFieldStepRangeMax;
2377 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
2379 _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
2380 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
2381 GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
2382 GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
2383 return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
2384 (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
2387 int GEOM_Displayer::SetDisplayMode( const int theMode )
2389 int aPrevMode = myDisplayMode;
2390 if ( theMode != -1 ) {
2391 myDisplayMode = theMode;
2392 myHasDisplayMode = true;
2400 int GEOM_Displayer::GetDisplayMode() const
2402 return myDisplayMode;
2405 int GEOM_Displayer::UnsetDisplayMode()
2407 int aPrevMode = myDisplayMode;
2408 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2409 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
2410 myHasDisplayMode = false;
2414 bool GEOM_Displayer::HasDisplayMode() const
2416 return myHasDisplayMode;
2419 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
2421 static QList<QColor> colors;
2423 if ( colors.isEmpty() ) {
2425 for (int s = 0; s < 2 ; s++)
2427 for (int v = 100; v >= 40; v = v - 20)
2429 for (int h = 0; h < 359 ; h = h + 60)
2431 colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
2437 static int currentColor = randomize( colors.size() );
2439 SALOMEDS::Color color;
2440 color.R = (double)colors[currentColor].red() / 255.0;
2441 color.G = (double)colors[currentColor].green() / 255.0;
2442 color.B = (double)colors[currentColor].blue() / 255.0;
2444 currentColor = (currentColor+1) % colors.count();
2449 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
2452 int aTolerance = 64;
2453 int anIterations = 0;
2459 if( anIterations % aPeriod == 0 )
2462 if( aTolerance < 1 )
2465 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
2467 aHue = (int)( 360.0 * rand() / RAND_MAX );
2468 //std::cout << "Hue = " << aHue << std::endl;
2470 //std::cout << "Auto colors : ";
2472 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
2473 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
2474 for( ; it != itEnd; ++it )
2476 SALOMEDS::Color anAutoColor = *it;
2477 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
2480 aQColor.getHsv( &h, &s, &v );
2481 //std::cout << h << " ";
2482 if( abs( h - aHue ) < aTolerance )
2485 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
2489 //std::cout << std::endl;
2495 //std::cout << "Hue of the returned color = " << aHue << std::endl;
2497 aColor.setHsv( aHue, 255, 255 );
2499 SALOMEDS::Color aSColor;
2500 aSColor.R = (double)aColor.red() / 255.0;
2501 aSColor.G = (double)aColor.green() / 255.0;
2502 aSColor.B = (double)aColor.blue() / 255.0;
2507 PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
2508 const QString& entry,
2511 // get default properties for the explicitly specified default view type
2512 PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
2514 if ( study && view ) {
2515 SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
2516 SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
2517 int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
2519 if ( viewModel && viewId != -1 ) {
2520 // get properties from the study
2521 PropMap storedMap = study->getObjectProperties( viewId, entry );
2522 // overwrite default properties from stored ones (that are specified)
2523 for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
2524 if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
2525 propMap.insert( GEOM::propertyName( (GEOM::Property)prop ),
2526 storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
2528 // ... specific processing for color
2529 // ... current implementation is to use same stored color for all aspects
2530 // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2531 if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2532 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2533 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2534 propMap.insert( GEOM::propertyName( GEOM::LineColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2535 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2536 propMap.insert( GEOM::propertyName( GEOM::PointColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2539 if ( !entry.isEmpty() ) {
2540 // get CORBA reference to geom object
2541 _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
2543 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
2544 if ( !CORBA::is_nil( object ) ) {
2545 GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
2546 if ( !CORBA::is_nil( geomObject ) ) { // to check
2547 // check that geom object has color properly set
2548 bool hasColor = false;
2549 SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
2550 // set color from geometry object (only once, if it is not yet set in GUI)
2551 // current implementation is to use same color for all aspects
2552 // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2553 if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2554 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
2555 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), objColor );
2556 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
2557 propMap.insert( GEOM::propertyName( GEOM::LineColor ), objColor );
2558 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), objColor );
2559 propMap.insert( GEOM::propertyName( GEOM::PointColor ), objColor );
2561 // check that object has point marker properly set
2562 GEOM::marker_type mType = geomObject->GetMarkerType();
2563 GEOM::marker_size mSize = geomObject->GetMarkerSize();
2564 int mTextureId = geomObject->GetMarkerTexture();
2565 bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) ||
2566 ( mType == GEOM::MT_USER && mTextureId > 0 );
2567 // set point marker from geometry object (only once, if it is not yet set in GUI)
2568 if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
2569 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
2571 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2572 QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
2574 else if ( mType == GEOM::MT_USER ) {
2576 propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
2588 PropMap GEOM_Displayer::getDefaultPropertyMap()
2592 // get resource manager
2593 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2595 // fill in the properties map with default values
2597 // - visibility (false by default)
2598 propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
2600 // - nb isos (take default value from preferences)
2601 propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
2602 QString( "%1%2%3" ).
2603 arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
2604 arg( GEOM::subSectionSeparator() ).
2605 arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
2607 // - transparency (opacity = 1-transparency)
2608 propMap.insert( GEOM::propertyName( GEOM::Transparency ),
2609 resMgr->integerValue( "Geometry", "transparency", 0 ) / 100. );
2611 // - display mode (take default value from preferences)
2612 propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
2613 resMgr->integerValue( "Geometry", "display_mode", 0 ) );
2615 // - show edges direction flag (false by default)
2616 propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
2618 // - show vertices flag (false by default)
2619 propMap.insert( GEOM::propertyName( GEOM::Vertices ), false );
2621 // - show name flag (false by default)
2622 propMap.insert( GEOM::propertyName( GEOM::ShowName ), false );
2624 // - shading color (take default value from preferences)
2625 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
2626 colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
2628 // - wireframe color (take default value from preferences)
2629 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
2630 colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
2632 // - standalone edges color (take default value from preferences)
2633 propMap.insert( GEOM::propertyName( GEOM::LineColor ),
2634 colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
2636 // - free boundaries color (take default value from preferences)
2637 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
2638 colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
2640 // - points color (take default value from preferences)
2641 propMap.insert( GEOM::propertyName( GEOM::PointColor ),
2642 colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
2644 // - isos color (take default value from preferences)
2645 propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
2646 colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
2648 // - outlines color (take default value from preferences)
2649 propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
2650 colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
2652 // - deflection coefficient (take default value from preferences)
2653 propMap.insert( GEOM::propertyName( GEOM::Deflection ),
2654 resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
2656 // - material (take default value from preferences)
2657 Material_Model material;
2658 material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
2659 propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
2661 // - edge width (take default value from preferences)
2662 propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
2663 resMgr->integerValue( "Geometry", "edge_width", 1 ) );
2665 // - isos width (take default value from preferences)
2666 propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
2667 resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
2669 // - point marker (take default value from preferences)
2670 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2671 QString( "%1%2%3" ).
2672 arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
2673 arg( GEOM::subSectionSeparator() ).
2674 arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2676 // - top-level flag (false by default)
2677 propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2682 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2683 SALOMEDS::Color aSColor;
2686 SUIT_Session* session = SUIT_Session::session();
2687 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2689 if ( app && !theGeomObject->_is_nil()) {
2690 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2693 _PTR(Study) aStudy = study->studyDS();
2694 aSColor = theGeomObject->GetColor();
2695 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2697 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2698 bool general_autocolor = true;
2699 #else // auto-color for groups only
2700 bool general_autocolor = false;
2701 #endif // GENERAL_AUTOCOLOR
2702 if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2703 GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2704 if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2705 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2706 aSColor = getPredefinedUniqueColor();
2708 #else // old algorithm for auto-colors
2709 QList<SALOMEDS::Color> aReservedColors;
2710 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2711 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2712 if ( aMainSObject ) {
2713 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2714 for ( ; it->More(); it->Next() ) {
2715 _PTR(SObject) aChildSObject( it->Value() );
2716 GEOM::GEOM_Object_var aChildObject =
2717 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2718 if ( CORBA::is_nil( aChildObject ) )
2721 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2722 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2723 aReservedColors.append( aReservedColor );
2726 aSColor = getUniqueColor( aReservedColors );
2728 #endif // SIMPLE_AUTOCOLOR
2738 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2739 const bool eraseOnlyChildren) {
2740 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2744 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2748 LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2753 // Erase from all views
2754 QList<SALOME_View*> views;
2756 ViewManagerList vmans = app->viewManagers();
2757 SUIT_ViewManager* vman;
2758 foreach ( vman, vmans ) {
2759 SUIT_ViewModel* vmod = vman->getViewModel();
2760 view = dynamic_cast<SALOME_View*> ( vmod );
2762 views.append( view );
2765 if( views.count() == 0 )
2768 //Erase childrens w/o update views
2769 DataObjectList listObj = parent->children( true );
2770 SUIT_DataObject* obj;
2771 foreach( obj, listObj ) {
2772 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2774 foreach ( view, views ) {
2775 Handle(SALOME_InteractiveObject) anIO =
2776 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2777 Erase(anIO, false, false, view);
2781 //Erase parent with view update or repaint views
2782 foreach ( view, views ) {
2783 if(!eraseOnlyChildren)
2784 Erase(theIO, false, true, view);
2790 void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
2792 if( theGeomFieldStep->_is_nil() )
2795 GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
2796 if( aGeomField->_is_nil() )
2799 GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
2800 if( aGeomFieldShape->_is_nil() )
2803 TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
2804 TCollection_AsciiString aFieldName( aGeomField->GetName() );
2805 TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
2807 aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
2809 GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
2811 int aFieldDimension = aGeomField->GetDimension();
2813 GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
2814 int aFieldNbComponents = aFieldComponents->length();
2816 QList<QVariant> aFieldStepData;
2817 if( aFieldDataType == GEOM::FDT_Bool )
2819 GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
2820 if ( !aGeomBoolFieldStep->_is_nil() )
2822 GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
2823 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2824 aFieldStepData << (bool)aValues[i];
2827 else if( aFieldDataType == GEOM::FDT_Int )
2829 GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
2830 if ( !aGeomIntFieldStep->_is_nil() )
2832 GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
2833 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2834 aFieldStepData << (qlonglong)aValues[i];
2837 else if( aFieldDataType == GEOM::FDT_Double )
2839 GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
2840 if ( !aGeomDoubleFieldStep->_is_nil() )
2842 GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
2843 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2844 aFieldStepData << (double)aValues[i];
2847 else if( aFieldDataType == GEOM::FDT_String )
2849 GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
2850 if ( !aGeomStringFieldStep->_is_nil() )
2852 GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
2853 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2854 aFieldStepData << QString( aValues[i] );
2858 double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
2859 aFieldStepData = groupFieldData( aFieldStepData,
2861 aFieldDataType == GEOM::FDT_String,
2863 aFieldStepRangeMax );
2865 setFieldStepInfo( aFieldDataType,
2870 aFieldStepRangeMax );
2873 QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
2874 const int theFieldNbComponents,
2875 const bool theIsString,
2876 double& theFieldStepRangeMin,
2877 double& theFieldStepRangeMax )
2879 QList<QVariant> aResultList;
2880 theFieldStepRangeMin = 0;
2881 theFieldStepRangeMax = 0;
2883 if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
2886 int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
2888 QList<QVariant> aGroupedList;
2890 bool anIsBoolean = false;
2891 for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
2894 QStringList aStringList;
2896 int aBaseIndex = aSubShape * theFieldNbComponents;
2897 for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
2899 int anIndex = aComponent + aBaseIndex;
2901 const QVariant& aVariant = theFieldStepData[ anIndex ];
2904 if( aVariant.type() == QVariant::String )
2905 aStringList << aVariant.toString();
2910 if( aVariant.type() == QVariant::Bool )
2912 aValue = aVariant.toBool() ? 1.0 : 0.0;
2918 if( aVariant.type() == QVariant::LongLong )
2919 aValue = double( aVariant.toLongLong() );
2920 else if( aVariant.type() == QVariant::Double )
2921 aValue = aVariant.toDouble();
2922 aNorm += aValue * aValue;
2928 aGroupedList << aStringList.join( "\n" );
2932 aNorm /= theFieldNbComponents;
2934 aNorm = pow( aNorm, 0.5 );
2936 if( aGroupedList.isEmpty() )
2937 theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
2940 theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
2941 theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
2944 aGroupedList << aNorm;
2950 theFieldStepRangeMin = 0.0;
2951 theFieldStepRangeMax = 1.0;
2954 SUIT_Session* session = SUIT_Session::session();
2955 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2956 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2958 QListIterator<QVariant> anIter( aGroupedList );
2959 while( anIter.hasNext() )
2961 const QVariant& aVariant = anIter.next();
2963 aResultList << aVariant;
2967 Quantity_Color aColor;
2968 if( FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2969 aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
2970 aResultList << aQColor;
2976 // Note: the method is copied from AIS_ColorScale class
2977 Standard_Integer GEOM_Displayer::HueFromValue( const Standard_Integer aValue,
2978 const Standard_Integer aMin,
2979 const Standard_Integer aMax )
2981 Standard_Integer minLimit( 0 ), maxLimit( 230 );
2983 Standard_Integer aHue = maxLimit;
2985 aHue = (Standard_Integer)( maxLimit - ( maxLimit - minLimit ) * ( aValue - aMin ) / ( aMax - aMin ) );
2987 aHue = Min( Max( minLimit, aHue ), maxLimit );
2992 // Note: the method is copied from AIS_ColorScale class
2993 Standard_Boolean GEOM_Displayer::FindColor( const Standard_Real aValue,
2994 const Standard_Real aMin,
2995 const Standard_Real aMax,
2996 const Standard_Integer ColorsCount,
2997 Quantity_Color& aColor )
2999 if( aValue<aMin || aValue>aMax || aMax<aMin )
3000 return Standard_False;
3004 Standard_Real IntervNumber = 0;
3007 else if( aValue>aMax )
3008 IntervNumber = ColorsCount-1;
3009 else if( Abs( aMax-aMin ) > Precision::Approximation() )
3010 IntervNumber = Floor( Standard_Real( ColorsCount ) * ( aValue - aMin ) / ( aMax - aMin ) ); // 'Ceiling' replaced with 'Floor'
3012 Standard_Integer Interv = Standard_Integer( IntervNumber );
3014 aColor = Quantity_Color( HueFromValue( Interv, 0, ColorsCount - 1 ), 1.0, 1.0, Quantity_TOC_HLS );
3016 return Standard_True;
3020 void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, const bool updateViewer )
3022 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
3026 SOCC_Viewer* aViewModel = dynamic_cast<SOCC_Viewer*>( GetActiveView() );
3030 #if OCC_VERSION_MAJOR < 7
3031 Handle(V3d_Viewer) aViewer = aViewModel->getViewer3d();
3032 if( aViewer.IsNull() )
3035 aViewer->InitActiveViews();
3036 if( !aViewer->MoreActiveViews() )
3039 Handle(V3d_View) aView = aViewer->ActiveView();
3040 if( aView.IsNull() )
3044 Standard_Boolean anIsDisplayColorScale = Standard_False;
3045 TCollection_AsciiString aColorScaleTitle;
3046 Standard_Real aColorScaleMin = 0, aColorScaleMax = 0;
3047 Standard_Boolean anIsBoolean = Standard_False;
3049 SALOME_ListIO aSelectedObjects;
3050 myApp->selectionMgr()->selectedObjects( aSelectedObjects );
3051 if( aSelectedObjects.Extent() == 1 )
3053 Handle(SALOME_InteractiveObject) anIO = aSelectedObjects.First();
3054 if( !anIO.IsNull() )
3056 SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( aViewModel->CreatePrs( anIO->getEntry() ) );
3059 AIS_ListOfInteractive aList;
3060 aPrs->GetObjects( aList );
3061 AIS_ListIteratorOfListOfInteractive anIter( aList );
3062 for( ; anIter.More(); anIter.Next() )
3064 Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() );
3065 if( !aShape.IsNull() )
3067 GEOM::field_data_type aFieldDataType;
3068 int aFieldDimension;
3069 QList<QVariant> aFieldStepData;
3070 TCollection_AsciiString aFieldStepName;
3071 double aFieldStepRangeMin, aFieldStepRangeMax;
3072 aShape->getFieldStepInfo( aFieldDataType,
3077 aFieldStepRangeMax );
3078 if( !aFieldStepData.isEmpty() && aFieldDataType != GEOM::FDT_String )
3080 anIsDisplayColorScale = Standard_True;
3081 aColorScaleTitle = aFieldStepName;
3082 aColorScaleMin = aFieldStepRangeMin;
3083 aColorScaleMax = aFieldStepRangeMax;
3084 anIsBoolean = aFieldDataType == GEOM::FDT_Bool;
3092 if( anIsDisplayColorScale )
3094 SUIT_Session* session = SUIT_Session::session();
3095 SUIT_ResourceMgr* resMgr = session->resourceMgr();
3097 Standard_Real anXPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
3098 Standard_Real anYPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
3099 Standard_Real aWidth = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
3100 Standard_Real aHeight = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
3101 Standard_Integer aTextHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
3102 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
3104 #if OCC_VERSION_MAJOR < 7
3105 Handle(Aspect_ColorScale) myColorScale = aView->ColorScale();
3106 if( !myColorScale.IsNull() )
3110 myColorScale->SetXPosition( anXPos );
3111 myColorScale->SetYPosition( anYPos );
3112 myColorScale->SetWidth( aWidth );
3113 myColorScale->SetHeight( aHeight );
3115 myColorScale->SetTextHeight( aTextHeight );
3116 myColorScale->SetNumberOfIntervals( anIsBoolean ? 2 : aNbIntervals );
3118 myColorScale->SetTitle( aColorScaleTitle );
3119 myColorScale->SetRange( aColorScaleMin, aColorScaleMax );
3121 #if OCC_VERSION_MAJOR < 7
3123 if( !aView->ColorScaleIsDisplayed() )
3124 aView->ColorScaleDisplay();
3127 if( aView->ColorScaleIsDisplayed() )
3128 aView->ColorScaleErase();
3130 if( !aViewModel->getAISContext()->IsDisplayed( myColorScale ) )
3131 aViewModel->getAISContext()->Display( myColorScale, Standard_True);
3134 if( aViewModel->getAISContext()->IsDisplayed( myColorScale ) )
3135 aViewModel->getAISContext()->Erase( myColorScale, Standard_True );
3138 if( theIsRedisplayFieldSteps )
3140 _PTR(Study) aStudyDS = aStudy->studyDS();
3141 QList<SUIT_ViewManager*> vmList;
3142 myApp->viewManagers( vmList );
3143 for( QList<SUIT_ViewManager*>::Iterator vmIt = vmList.begin(); vmIt != vmList.end(); vmIt++ )
3145 if( SUIT_ViewManager* aViewManager = *vmIt )
3147 const ObjMap& anObjects = aStudy->getObjectProperties( aViewManager->getGlobalId() );
3148 for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ )
3150 _PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) );
3153 CORBA::Object_var anObject = GeometryGUI::ClientSObjectToObject( aSObj );
3154 if( !CORBA::is_nil( anObject ) )
3156 GEOM::GEOM_FieldStep_var aFieldStep = GEOM::GEOM_FieldStep::_narrow( anObject );
3157 if( !aFieldStep->_is_nil() )
3159 CORBA::String_var aStepEntry = aFieldStep->GetStudyEntry();
3160 Handle(SALOME_InteractiveObject) aStepIO =
3161 new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" );
3162 Redisplay( aStepIO, false, false );