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 "GEOMGUI_DimensionProperty.h"
29 #include "GeometryGUI.h"
31 #include <GEOM_Constants.h>
32 #include <GEOM_TypeFilter.h>
33 #include <GEOM_EdgeFilter.h>
34 #include <GEOM_FaceFilter.h>
35 #include <GEOM_CompoundFilter.h>
36 #include <GEOM_PreviewFilter.h>
37 #include <GEOM_LogicalFilter.h>
38 #include <GEOM_OCCFilter.h>
40 #include <GEOM_Actor.h>
41 #include <GEOM_AISShape.hxx>
42 #include <GEOM_AISDimension.hxx>
43 #include <GEOM_TopWireframeShape.hxx>
44 #include <GEOM_AISVector.hxx>
45 #include <GEOM_AISTrihedron.hxx>
46 #include <GEOM_VTKTrihedron.hxx>
47 #include <GEOM_VTKPropertyMaterial.hxx>
49 #include <GEOMUtils.hxx>
51 #include <Material_Model.h>
53 #include <SUIT_Desktop.h>
54 #include <SUIT_ViewWindow.h>
55 #include <SUIT_Session.h>
56 #include <SUIT_ViewManager.h>
57 #include <SUIT_ResourceMgr.h>
59 #include <Basics_OCCTVersion.hxx>
61 #include <SalomeApp_Study.h>
62 #include <SalomeApp_Application.h>
63 #include <LightApp_SelectionMgr.h>
64 #include <LightApp_DataObject.h>
65 #include <SalomeApp_TypeFilter.h>
66 #include <SalomeApp_Tools.h>
67 #include "utilities.h"
69 #include <SALOME_ListIO.hxx>
70 #include <SALOME_Prs.h>
71 #include "utilities.h"
74 #include <SOCC_ViewModel.h>
77 #include <SVTK_ViewModel.h>
79 #include <OCCViewer_ViewWindow.h>
80 #include <OCCViewer_ViewPort3d.h>
81 #include <OCCViewer_Utilities.h>
84 #include <AIS_Dimension.hxx>
85 #include <AIS_LengthDimension.hxx>
86 #include <AIS_DiameterDimension.hxx>
87 #include <AIS_AngleDimension.hxx>
88 #include <AIS_ListIteratorOfListOfInteractive.hxx>
89 #include <Aspect_PolygonOffsetMode.hxx>
90 #include <Aspect_ColorScale.hxx>
91 #include <Prs3d_IsoAspect.hxx>
92 #include <Prs3d_PointAspect.hxx>
93 #include <StdSelect_TypeOfEdge.hxx>
94 #include <StdSelect_TypeOfFace.hxx>
95 #include <StdSelect_DisplayMode.hxx>
96 #include <TopoDS_Face.hxx>
97 #include <BRep_Tool.hxx>
98 #include <Geom_Plane.hxx>
99 #include <Geom_Axis2Placement.hxx>
100 #include <Graphic3d_AspectFillArea3d.hxx>
101 #include <gp_Pln.hxx>
102 #include <TColStd_MapOfInteger.hxx>
103 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
104 #include <TopoDS_Iterator.hxx>
105 #include <Graphic3d_AspectMarker3d.hxx>
106 #include <TopTools_MapOfShape.hxx>
107 #include <TopTools_ListOfShape.hxx>
108 #include <TopTools_ListIteratorOfListOfShape.hxx>
109 #include <TopoDS.hxx>
110 #include <NCollection_DataMap.hxx>
111 #include <NCollection_Map.hxx>
113 #include <Prs3d_ShadingAspect.hxx>
115 #include <BRepMesh_IncrementalMesh.hxx>
118 #include <vtkActorCollection.h>
119 #include <vtkProperty.h>
122 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
124 #include <GEOMImpl_Types.hxx>
126 #include <TColStd_HArray1OfByte.hxx>
128 // If the next macro is defined, autocolor feature works for all sub-shapes;
129 // if it is undefined, autocolor feature works for groups only
130 #define GENERAL_AUTOCOLOR
131 // Below macro, when uncommented, switches on simplified (more performant) algorithm
132 // of auto-color picking up
133 #define SIMPLE_AUTOCOLOR
135 // Hard-coded value of shape deflection coefficient for VTK viewer
136 const double VTK_MIN_DEFLECTION = 0.001;
137 // If the next macro is defined, the deflection coefficient for VTK presentation
138 // is limited by VTK_MIN_DEFLECTION
139 //#define LIMIT_DEFLECTION_FOR_VTK
141 // Pixmap caching support
144 typedef NCollection_Map<Handle(GEOM_AISShape)> SetOfAISShapes;
145 typedef NCollection_DataMap<Handle(Image_PixMap), SetOfAISShapes> PixmapUsageMap;
146 typedef QMap<QString, Handle(Image_PixMap)> PixmapCacheMap;
148 static inline PixmapUsageMap& getPixmapUsageMap()
150 static PixmapUsageMap aMap;
154 static inline PixmapCacheMap& getPixmapCacheMap()
156 static PixmapCacheMap aMap;
160 //===========================================================================
161 // Function : getDefaultTexture
162 // Purpose : Get default texture
163 //===========================================================================
164 static inline Handle(Image_PixMap) getDefaultTexture()
166 static Handle(Image_PixMap) aPixmap;
167 if ( aPixmap.IsNull() ) {
168 QPixmap px(":images/default_texture.png");
170 aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage() );
175 //===========================================================================
176 // Function : cacheTextureFor
177 // Purpose : Load and cache image for the specified presentation.
178 //===========================================================================
179 static inline Handle(Image_PixMap) cacheTextureFor( const QString& thePath,
180 const Handle(GEOM_AISShape)& theShape )
182 if ( thePath.isEmpty() )
185 PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
186 PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
188 Handle(Image_PixMap) aPixmap = aPixmapCacheMap.value( thePath, NULL );
189 if ( !aPixmap.IsNull() ) {
190 // point that the texture is used by the presentation
191 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
192 aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
194 aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
199 // convert texture to compatible image format
200 QImage anImage = QImage( thePath ).convertToFormat( QImage::Format_ARGB32 );
201 if ( anImage.isNull() )
204 aPixmap = OCCViewer_Utilities::imageToPixmap( anImage );
206 aPixmapCacheMap.insert( thePath, aPixmap );
208 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
209 aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
211 aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
216 //===========================================================================
217 // Function : releaseTextures
218 // Purpose : Releases cached textures found for the specified presentation.
219 //===========================================================================
220 static inline void releaseTextures( const SALOME_OCCPrs* thePrs )
222 const SOCC_Prs* anOccPrs = dynamic_cast<const SOCC_Prs*>( thePrs );
224 AIS_ListOfInteractive aListOfIO;
226 anOccPrs->GetObjects( aListOfIO );
228 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
230 PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
231 PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
233 for ( ; aIterateIO.More(); aIterateIO.Next() )
235 Handle(GEOM_AISShape) aAISShape =
236 Handle(GEOM_AISShape)::DownCast( aIterateIO.Value() );
238 if ( aAISShape.IsNull() )
241 #ifdef USE_TEXTURED_SHAPE
242 const Handle(Image_PixMap)& aPixmap = aAISShape->TexturePixMap();
243 if ( aPixmap.IsNull() )
246 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
249 SetOfAISShapes& aUsersShapes = aPixmapUsersMap.ChangeFind( aPixmap );
251 aUsersShapes.Remove( aAISShape );
253 if ( aUsersShapes.IsEmpty() ) {
254 aPixmapUsersMap.UnBind( aPixmap );
255 aPixmapCacheMap.remove( aPixmapCacheMap.key( aPixmap ) );
261 uint randomize( uint size )
263 static bool initialized = false;
264 if ( !initialized ) {
265 qsrand( QDateTime::currentDateTime().toTime_t() );
269 v = uint( (double)( v ) / RAND_MAX * size );
270 v = qMax( uint(0), qMin ( v, size-1 ) );
275 //================================================================
276 // Function : getActiveStudy
277 // Purpose : Get active study, returns 0 if no open study frame
278 //================================================================
279 static inline SalomeApp_Study* getActiveStudy()
281 SUIT_Session* session = SUIT_Session::session();
282 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
284 return ( SalomeApp_Study* )app->activeStudy();
288 static inline int getViewManagerId( SALOME_View* theViewFrame) {
289 SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
290 SUIT_ViewManager* aViewMgr = 0;
292 aViewMgr = aModel->getViewManager();
293 return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
296 //================================================================
297 // Function : getTopAbsMode
298 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
299 // one from GEOMImpl_Types.h
300 //================================================================
301 static inline int getTopAbsMode( const int implType )
305 case GEOM_COMPOUND : return TopAbs_COMPOUND;
306 case GEOM_SOLID : return TopAbs_SOLID;
307 case GEOM_SHELL : return TopAbs_SHELL;
308 case GEOM_FACE : return TopAbs_FACE;
309 case GEOM_WIRE : return TopAbs_WIRE;
310 case GEOM_EDGE : return TopAbs_EDGE;
311 case GEOM_POINT : return TopAbs_VERTEX;
316 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
318 if ( shape.IsNull() )
321 int ret = shape.ShapeType();
323 if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
324 TopoDS_Iterator it(shape, Standard_True, Standard_False);
325 for (; it.More(); it.Next()) {
326 TopoDS_Shape sub_shape = it.Value();
327 if ( sub_shape.IsNull() ) continue;
328 int stype = getMinMaxShapeType( sub_shape, ismin );
329 if ( stype == TopAbs_SHAPE ) continue;
330 if ( ismin && stype > ret )
332 else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
340 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
342 return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
345 //================================================================
346 // Function : getFilter
347 // Purpose : Get filter corresponding to the type of object
348 // from GEOMImpl_Types.h
349 //================================================================
350 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
352 SUIT_SelectionFilter* aFilter;
354 int aTopAbsMode = getTopAbsMode( theMode );
355 if ( aTopAbsMode != -1 )
356 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
360 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
361 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
363 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
364 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
365 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
366 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
367 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
368 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
370 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
372 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
373 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
375 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
381 //================================================================
382 // Function : getComplexFilter
383 // Purpose : Get compound filter corresponding to the type of
384 // object from GEOMImpl_Types.h
385 //================================================================
386 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
388 GEOM_CompoundFilter* aFilter;
390 if(aSubShapes != NULL ) {
391 aFilter = new GEOM_CompoundFilter(getStudy());
392 QList<int> aTopAbsTypes;
393 QList<int>::const_iterator it;
394 for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
395 int topAbsMode = getTopAbsMode(*it);
396 if(topAbsMode != -1 )
397 aTopAbsTypes.append(topAbsMode);
399 aFilter->addSubTypes(aTopAbsTypes);
405 //================================================================
406 // Function : getEntry
408 //================================================================
409 static std::string getEntry( GEOM::GEOM_BaseObject_ptr object )
411 SUIT_Session* session = SUIT_Session::session();
412 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
415 CORBA::String_var IOR = app->orb()->object_to_string( object );
416 if ( strcmp(IOR.in(), "") != 0 )
418 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
419 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
427 //================================================================
428 // Function : getName
430 //================================================================
431 static std::string getName( GEOM::GEOM_BaseObject_ptr object )
433 SUIT_Session* session = SUIT_Session::session();
434 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
437 CORBA::String_var IOR = app->orb()->object_to_string( object );
438 if ( strcmp(IOR.in(), "") != 0 )
440 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
441 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
443 _PTR(GenericAttribute) anAttr;
445 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
447 _PTR(AttributeName) aNameAttr( anAttr );
448 return aNameAttr->Value();
456 //=================================================================
458 * GEOM_Displayer::GEOM_Displayer
461 //=================================================================
462 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
465 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
470 SUIT_Session* session = SUIT_Session::session();
471 SUIT_ResourceMgr* resMgr = session->resourceMgr();
473 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
474 myShadingColor = SalomeApp_Tools::color( col );
476 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
477 myHasDisplayMode = false;
479 int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
481 myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
482 myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
483 myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
485 // Next properties provide a way to customize displaying of presentations;
486 // for instance, this is useful for preview
496 // This parameter is used for activisation/deactivisation (selection) of objects to be displayed
499 // Activate parallel vizualisation only for testing purpose
500 // and if the corresponding env variable is set to 1
501 char* parallel_visu = getenv("PARALLEL_VISU");
502 if (parallel_visu && atoi(parallel_visu))
504 MESSAGE("Parallel visualisation on");
505 BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
510 myFieldDataType = GEOM::FDT_Double;
511 myFieldDimension = 0;
512 myFieldStepRangeMin = 0;
513 myFieldStepRangeMax = 0;
516 //=================================================================
518 * GEOM_Displayer::~GEOM_Displayer
521 //=================================================================
522 GEOM_Displayer::~GEOM_Displayer()
526 //=================================================================
528 * GEOM_Displayer::Display
529 * Display interactive object in the current viewer
531 //=================================================================
532 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
533 const bool updateViewer,
534 SALOME_View* theViewFrame )
536 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
539 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
543 vf->BeforeDisplay( this, prs );
544 vf->Display( this, prs );
545 vf->AfterDisplay( this, prs );
550 delete prs; // delete presentation because displayer is its owner
555 //=================================================================
557 * GEOM_Displayer::Display
558 * This overloaded Display() method can be useful for operations
559 * not using dialog boxes.
561 //=================================================================
562 void GEOM_Displayer::Display( GEOM::GEOM_BaseObject_ptr theObj, const bool updateViewer )
564 if ( theObj->_is_nil() )
567 std::string entry = getEntry( theObj );
569 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
574 //=================================================================
576 * GEOM_Displayer::Erase
577 * Erase interactive object in the current viewer
579 //=================================================================
580 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
582 const bool updateViewer,
583 SALOME_View* theViewFrame )
585 if ( theIO.IsNull() )
588 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
591 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
593 vf->BeforeErase( this, prs );
594 vf->Erase( this, prs, forced );
595 vf->AfterErase( this, prs );
598 delete prs; // delete presentation because displayer is its owner
603 //=================================================================
605 * GEOM_Displayer::Erase
606 * Erase geometry object in the current viewer
608 //=================================================================
609 void GEOM_Displayer::Erase( GEOM::GEOM_BaseObject_ptr theObj,
611 const bool updateViewer,
612 SALOME_View* theViewFrame)
614 std::string entry = getEntry( theObj );
617 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
618 forced, updateViewer, theViewFrame);
622 //=================================================================
624 * GEOM_Displayer::Redisplay
625 * Redisplay (erase and then display again) interactive object
626 * in the current viewer
628 //=================================================================
629 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
630 const bool updateViewer,
631 const bool checkActiveViewer )
633 // Remove the object permanently (<forced> == true)
634 SUIT_Session* ses = SUIT_Session::session();
635 SUIT_Application* app = ses->activeApplication();
638 SUIT_Desktop* desk = app->desktop();
639 QList<SUIT_ViewWindow*> wnds = desk->windows();
640 SUIT_ViewWindow* wnd;
641 QListIterator<SUIT_ViewWindow*> it( wnds );
642 while ( it.hasNext() && (wnd = it.next()) )
644 SUIT_ViewManager* vman = wnd->getViewManager();
647 SUIT_ViewModel* vmodel = vman->getViewModel();
650 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
653 if ( view->isVisible( theIO ) || ( checkActiveViewer && view == GetActiveView() ) )
655 Redisplay( theIO, updateViewer, view );
664 //=================================================================
666 * GEOM_Displayer::Redisplay
667 * Redisplay (erase and then display again) interactive object
668 * in the specified view
670 //=================================================================
671 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
672 const bool theUpdateViewer,
673 SALOME_View* theViewFrame )
675 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
681 Erase( theIO, true, false, theViewFrame );
682 Display( theIO, theUpdateViewer, theViewFrame );
685 //=================================================================
687 * GEOM_Displayer::Display
688 * Calls Display() method for each object in the given list
690 //=================================================================
691 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
693 SALOME_ListIteratorOfListIO Iter( theIOList );
694 for ( ; Iter.More(); Iter.Next() ) {
695 Display( Iter.Value(), false );
701 void GEOM_Displayer::UpdateVisibility( SALOME_View* v, const SALOME_Prs* p, bool on )
703 SalomeApp_Study* aStudy = getStudy();
705 if ( v ) vId = getViewManagerId( v );
708 QString entry = p->GetEntry();
709 if ( !entry.isEmpty() ) {
711 aStudy->setObjectProperty( vId, entry, GEOM::propertyName( GEOM::Visibility ), on );
712 setVisibilityState( entry, on ? Qtx::ShownState : Qtx::HiddenState );
717 aStudy->setObjectProperty( vId, GEOM::propertyName( GEOM::Visibility ), on );
722 Quantity_Color GEOM_Displayer::qColorFromResources( const QString& property, const QColor& defColor )
724 // VSR: this method can be improved in future:
725 // to improve performance, the default values from resource manager should be cached in the displayer
726 return SalomeApp_Tools::color( SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor ) );
729 QColor GEOM_Displayer::colorFromResources( const QString& property, const QColor& defColor )
731 // VSR: this method can be improved in future:
732 // to improve performance, the default values from resource manager should be cached in the displayer
733 return SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor );
736 void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShape, bool create )
738 // check that shape is not null
739 if ( AISShape.IsNull() ) return;
741 // check that study is active
742 SalomeApp_Study* study = getStudy();
743 if ( !study ) return;
745 if ( myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
746 !TopoDS_Iterator(myShape).More() )
747 return; // NPAL15983 (Bug when displaying empty groups)
749 // set interactive object
751 Handle( SALOME_InteractiveObject ) anIO;
753 if ( !myIO.IsNull() ) {
754 AISShape->setIO( myIO );
755 AISShape->SetOwner( myIO );
758 else if ( !myName.empty() ) {
759 // workaround to allow selection of temporary objects
760 static int tempId = 0;
761 anIO = new SALOME_InteractiveObject( QString( "TEMP_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
762 AISShape->setIO( anIO );
763 AISShape->SetOwner( anIO );
766 // flag: only vertex or compound of vertices is processed (specific handling)
767 bool onlyVertex = myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape );
768 // presentation study entry (empty for temporary objects like preview)
769 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
770 // flag: temporary object
771 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
772 // currently active view window's ID (-1 if no active view)
773 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
775 // get presentation properties
776 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
778 // Temporary staff: vertex must be infinite for correct visualization
779 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
782 Material_Model material;
783 // if predefined color isn't set in displayer(via GEOM_Displayer::SetColor() function)
785 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
786 // - set front material properties
787 AISShape->SetCurrentFacingModel( Aspect_TOFM_FRONT_SIDE );
788 AISShape->SetMaterial( material.getMaterialOCCAspect( true ) );
789 // - set back material properties
790 AISShape->SetCurrentFacingModel( Aspect_TOFM_BACK_SIDE );
791 AISShape->SetMaterial( material.getMaterialOCCAspect( false ) );
792 // - switch to default (both sides) facing mode
793 AISShape->SetCurrentFacingModel( Aspect_TOFM_BOTH_SIDE );
799 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function;
800 // we set it to the shape not taking into account material properties
801 AISShape->SetShadingColor( (Quantity_NameOfColor)GetColor() );
803 else if ( !material.isPhysical() ) {
804 // shading color from properties is used only for non-physical materials
805 AISShape->SetShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>() ) );
809 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
810 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
811 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
812 AISShape->Attributes()->SetLineAspect( anAspect );
814 // - unfree boundaries color
815 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
816 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
817 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
818 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
820 // - free boundaries color
821 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
822 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
823 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>() ) );
824 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
826 // - standalone edges color
827 anAspect = AISShape->Attributes()->WireAspect();
828 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
829 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>() ) );
830 AISShape->Attributes()->SetWireAspect( anAspect );
832 // - color for edges in shading+edges mode
833 AISShape->SetEdgesInShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
835 // - color of labels (textual fields and shape name)
836 AISShape->SetLabelColor( qColorFromResources( "label_color", QColor( 255, 255, 255 ) ) );
839 AISShape->SetDisplayMode( HasDisplayMode() ?
840 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
842 // display mode from properties
843 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt() );
845 // - face boundaries color and line width
846 anAspect = AISShape->Attributes()->FaceBoundaryAspect();
847 anAspect->SetColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
848 anAspect->SetWidth( HasWidth() ? GetWidth() : propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
849 AISShape->Attributes()->SetFaceBoundaryAspect( anAspect );
851 // set display vectors flag
852 AISShape->SetDisplayVectors( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
854 // set display vertices flag
855 bool isVerticesMode = propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool();
856 AISShape->SetDisplayVertices( isVerticesMode );
858 // set display name flag
859 bool isNameMode = propMap.value( GEOM::propertyName( GEOM::ShowName ) ).toBool();
860 AISShape->SetDisplayName( isNameMode );
863 if( HasTransparency() ) {
864 AISShape->SetTransparency( GetTransparency() );
866 AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
869 // set iso properties
870 int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt();
871 int vIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[1].toInt();
872 Quantity_Color isosColor = SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>() );
873 int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt();
874 Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect();
875 Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect();
877 if ( HasIsosColor() ) {
878 uIsoAspect->SetColor( (Quantity_NameOfColor)GetIsosColor() );
879 vIsoAspect->SetColor( (Quantity_NameOfColor)GetIsosColor() );
882 uIsoAspect->SetColor( isosColor );
883 vIsoAspect->SetColor( isosColor );
886 if ( HasIsosWidth() ) {
887 uIsoAspect->SetWidth( GetIsosWidth() );
888 vIsoAspect->SetWidth( GetIsosWidth() );
891 uIsoAspect->SetWidth( isosWidth );
892 vIsoAspect->SetWidth( isosWidth );
896 uIsoAspect->SetNumber( GetNbIsos() );
897 vIsoAspect->SetNumber( GetNbIsos() );
900 uIsoAspect->SetNumber( uIsos );
901 vIsoAspect->SetNumber( vIsos );
904 AISShape->Attributes()->SetUIsoAspect( uIsoAspect );
905 AISShape->Attributes()->SetVIsoAspect( vIsoAspect );
907 // set deflection coefficient
908 // ... to avoid to small values of the coefficient, its lower value is limited
909 AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) );
913 if ( HasTexture() ) {
914 // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function
915 aImagePath = GetTexture().c_str();
916 if ( ! entry.isEmpty() ) {
917 // check that study is active
918 SalomeApp_Study* study = getActiveStudy();
920 // Store the texture in object properties for next displays
921 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) );
922 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
924 // Update propeties map
925 propMap = getObjectProperties( study, entry, myViewFrame );
930 aImagePath = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
933 #ifdef USE_TEXTURED_SHAPE
934 Handle(Image_PixMap) aPixmap;
935 if ( !aImagePath.isEmpty() )
936 aPixmap = cacheTextureFor( aImagePath, AISShape );
938 aPixmap = getDefaultTexture();
940 // apply image to shape
941 if ( !aPixmap.IsNull() ) {
942 AISShape->SetTexturePixMap( aPixmap );
943 AISShape->SetTextureMapOn();
944 AISShape->DisableTextureModulate();
947 AISShape->SetTextureMapOff();
952 AISShape->SetWidth( HasWidth() ?
953 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
955 // libe width from properties
956 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
958 // set top-level flag
959 AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
961 // set point marker (for vertex / compound of vertices only)
962 if ( onlyVertex || isVerticesMode ) {
963 QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
964 if ( aList.size() == 2 ) {
965 // standard marker string contains "TypeOfMarker:ScaleOfMarker"
966 int aTypeOfMarker = aList[0].toInt();
967 double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
968 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
969 anAspect->SetScale( aScaleOfMarker );
970 anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
971 anAspect->SetColor( HasColor() ?
972 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
973 (Quantity_NameOfColor)GetColor() :
974 // color from properties
975 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ) );
976 AISShape->Attributes()->SetPointAspect( anAspect );
978 else if ( aList.size() == 1 ) {
979 // custom marker string contains "IdOfTexture"
980 int textureId = aList[0].toInt();
981 Standard_Integer aWidth, aHeight;
982 Handle(TColStd_HArray1OfByte) aTexture =
983 GeometryGUI::getTexture( study, textureId, aWidth, aHeight );
984 if ( !aTexture.IsNull() ) {
985 Handle(Prs3d_PointAspect) aTextureAspect =
986 new Prs3d_PointAspect( HasColor() ?
987 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
988 (Quantity_NameOfColor)GetColor() :
989 // color from properties
990 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
993 AISShape->Attributes()->SetPointAspect( aTextureAspect );
998 // set field step data
999 AISShape->setFieldStepInfo( myFieldDataType,
1003 myFieldStepRangeMin,
1004 myFieldStepRangeMax );
1006 if ( create && !isTemporary && aMgrId != -1 ) {
1007 // set properties to the study
1008 study->setObjectProperties( aMgrId, entry, propMap );
1011 // AISShape->SetName(???); ??? necessary to set name ???
1014 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
1016 // check that actor is not null
1017 if ( !actor ) return;
1019 // check that study is active
1020 SalomeApp_Study* study = getStudy();
1021 if ( !study ) return;
1023 // set interactive object
1025 Handle( SALOME_InteractiveObject ) anIO;
1027 if ( !myIO.IsNull() ) {
1028 actor->setIO( myIO );
1031 else if ( !myName.empty() ) {
1032 // workaround to allow selection of temporary objects
1033 static int tempId = 0;
1034 anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
1035 actor->setIO( anIO );
1038 // presentation study entry (empty for temporary objects like preview)
1039 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
1040 // flag: temporary object
1041 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
1042 // currently active view window's ID (-1 if no active view)
1043 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
1045 // get presentation properties
1046 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
1049 /////////////////////////////////////////////////////////////////////////
1050 // VSR: for VTK viewer currently deflection coefficient is hardcoded
1051 // due to performance problem
1052 // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
1053 /////////////////////////////////////////////////////////////////////////
1054 if ( !actor->getTopo().IsSame( myShape ) )
1055 #ifdef LIMIT_DEFLECTION_FOR_VTK
1056 actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
1058 actor->SetShape( myShape, qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ), myType == GEOM_VECTOR );
1062 Material_Model material;
1063 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
1064 std::vector<vtkProperty*> mprops;
1065 mprops.push_back( material.getMaterialVTKProperty( true ) );
1066 mprops.push_back( material.getMaterialVTKProperty( false) );
1067 actor->SetMaterial( mprops );
1069 // set iso-lines properties
1071 // - set number of iso-lines
1072 int nbIsos[2]= { 1, 1 };
1073 if ( HasNbIsos() ) {
1074 nbIsos[0] = GetNbIsos();
1075 nbIsos[1] = GetNbIsos();
1078 QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
1079 nbIsos[0] = isos[0].toInt();
1080 nbIsos[1] = isos[1].toInt();
1082 actor->SetNbIsos( nbIsos );
1084 // - set iso-lines width
1085 actor->SetIsosWidth( HasIsosWidth() ? GetIsosWidth() : propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
1087 // - set iso-lines color
1088 if ( HasIsosColor() )
1089 c = SalomeApp_Tools::color( Quantity_Color((Quantity_NameOfColor)GetIsosColor()) );
1091 c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
1092 actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
1097 // - same color for all sub-actors
1098 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1099 actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1102 // shading color (for non-physical materials)
1103 if ( !material.isPhysical() ) {
1104 c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
1105 actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1106 actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1109 // - standalone edge color
1110 c = propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>();
1111 actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1113 c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
1114 // - shared edges color ???
1115 actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1117 c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
1118 // - free edges color ???
1119 actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
1122 c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
1123 actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
1126 // - color for edges in shading+edges mode
1127 c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
1128 actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
1130 // - color of labels (shape name)
1131 c = colorFromResources( "label_color", QColor( 255, 255, 255 ) );
1132 actor->SetLabelColor( c.redF(), c.greenF(), c.blueF() );
1135 if( HasTransparency() ) {
1136 actor->SetOpacity( 1.0 - GetTransparency() );
1138 actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
1142 actor->SetWidth( HasWidth() ?
1143 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1145 // libe width from properties
1146 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
1148 // set display vectors flag
1149 actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
1151 // set display vertices flag
1152 actor->SetVerticesMode( propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool() );
1154 // set display name flag
1155 actor->SetNameMode( propMap.value( GEOM::propertyName( GEOM::ShowName ) ).toBool() );
1158 int displayMode = HasDisplayMode() ?
1159 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
1161 // display mode from properties
1162 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
1164 // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
1165 // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
1166 // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
1167 // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
1169 if ( displayMode == 2 )
1170 // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
1171 // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
1173 actor->setDisplayMode( displayMode );
1176 actor->PickableOn();
1178 actor->PickableOff();
1180 if ( create && !isTemporary && aMgrId != -1 ) {
1181 // set properties to the study
1182 study->setObjectProperties( aMgrId, entry, propMap );
1186 //=================================================================
1188 * GEOM_Displayer::updateDimensions
1189 * Creates or renews dimension presentation for the IO.
1191 //=================================================================
1192 void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& theIO,
1193 SALOME_OCCPrs* thePrs,
1194 const gp_Ax3& theShapeLCS )
1196 SalomeApp_Study* aStudy = getStudy();
1202 if ( theIO.IsNull() )
1207 SOCC_Prs* anOccPrs = dynamic_cast<SOCC_Prs*>( thePrs );
1209 AIS_ListOfInteractive aListOfIO;
1211 anOccPrs->GetObjects( aListOfIO );
1213 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
1215 // remove outdated presentations of dimensions
1216 for ( ; aIterateIO.More(); aIterateIO.Next() )
1218 const Handle(AIS_InteractiveObject)& anIO = aIterateIO.Value();
1219 if ( !anIO->IsKind( STANDARD_TYPE( AIS_Dimension ) ) )
1224 aListOfIO.Remove( aIterateIO );
1226 if ( !aIterateIO.More() )
1232 // prepare dimension styling
1233 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1235 QColor aQColor = aResMgr->colorValue ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
1236 int aLineWidth = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
1237 QFont aFont = aResMgr->fontValue ( "Geometry", "dimensions_font", QFont("Y14.5M-2009", 14) );
1238 double anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
1239 bool isUnitsShown = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
1240 QString aUnitsLength = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
1241 QString aUnitsAngle = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
1242 bool aUseText3d = aResMgr->booleanValue( "Geometry", "dimensions_use_text3d", false );
1244 // restore dimension presentation from saved attribute or property data
1245 AIS_ListOfInteractive aRestoredDimensions;
1247 QVariant aProperty = aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1249 GEOM::propertyName( GEOM::Dimensions ),
1252 GEOMGUI_DimensionProperty aRecords;
1254 if ( aProperty.isValid() && aProperty.canConvert<GEOMGUI_DimensionProperty>() )
1256 aRecords = aProperty.value<GEOMGUI_DimensionProperty>();
1260 aRecords.LoadFromAttribute( getStudy(), theIO->getEntry() );
1263 // create up-to-date dimension presentations
1264 for ( int aPrsIt = 0; aPrsIt < aRecords.GetNumber(); ++aPrsIt )
1266 if ( !aRecords.IsVisible( aPrsIt ) )
1271 // init dimension by type
1272 Handle(AIS_Dimension) aPrs;
1273 switch( aRecords.GetType( aPrsIt ) )
1275 case GEOMGUI_DimensionProperty::DimensionType_Length :
1277 Handle(GEOM_AISLength) aLength = new GEOM_AISLength( aPrsIt );
1278 aRecords.GetRecord( aPrsIt )->AsLength()->Update( aLength, theShapeLCS );
1283 case GEOMGUI_DimensionProperty::DimensionType_Diameter :
1285 Handle(GEOM_AISDiameter) aDiam = new GEOM_AISDiameter( aPrsIt );
1286 aRecords.GetRecord( aPrsIt )->AsDiameter()->Update( aDiam, theShapeLCS );
1291 case GEOMGUI_DimensionProperty::DimensionType_Angle :
1293 Handle(GEOM_AISAngle) anAng = new GEOM_AISAngle( aPrsIt );
1294 aRecords.GetRecord( aPrsIt )->AsAngle()->Update( anAng, theShapeLCS );
1300 aPrs->SetOwner( theIO );
1302 Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
1304 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
1306 aStyle->SetCommonColor( aColor );
1307 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1308 aStyle->MakeText3d( aUseText3d );
1309 aStyle->MakeTextShaded( Standard_True );
1310 int fsize = aFont.pixelSize() != -1 ? aFont.pixelSize() : aFont.pointSize();
1311 aStyle->SetExtensionSize( fsize * 0.5 );
1312 aStyle->TextAspect()->SetFont( aFont.family().toLatin1().data() );
1313 aStyle->TextAspect()->SetHeight( fsize );
1314 aStyle->ArrowAspect()->SetLength( anArrowLength );
1315 aStyle->LineAspect()->SetWidth( aLineWidth );
1316 aStyle->SetTextHorizontalPosition( aPrs->DimensionAspect()->TextHorizontalPosition() );
1317 aStyle->SetTextVerticalPosition( aPrs->DimensionAspect()->TextVerticalPosition() );
1318 aStyle->SetArrowOrientation( aPrs->DimensionAspect()->ArrowOrientation() );
1319 aPrs->SetDimensionAspect( aStyle );
1320 aPrs->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
1321 aPrs->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
1322 aPrs->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
1324 if ( aPrs->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
1326 // show degree symbol for dimension instead of label "deg"
1327 if ( aUnitsAngle == "deg" )
1329 aPrs->SetSpecialSymbol(0xB0);
1330 aPrs->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
1331 aStyle->MakeUnitsDisplayed(Standard_False);
1335 aPrs->SetDisplaySpecialSymbol(AIS_DSS_No);
1336 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1341 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1344 aListOfIO.Append( aPrs );
1347 // update presentation
1350 for ( aIterateIO.Initialize( aListOfIO ); aIterateIO.More(); aIterateIO.Next() )
1352 anOccPrs->AddObject( aIterateIO.Value() );
1356 //=================================================================
1358 * GEOM_Displayer::Erase
1359 * Calls Erase() method for each object in the given list
1361 //=================================================================
1362 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
1364 const bool updateViewer )
1366 SALOME_ListIteratorOfListIO Iter( theIOList );
1367 for ( ; Iter.More(); Iter.Next() )
1368 Erase( Iter.Value(), forced, false );
1374 //=================================================================
1376 * GEOM_Displayer::Redisplay
1377 * Calls Redisplay() method for each object in the given list
1379 //=================================================================
1380 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1381 const bool updateViewer,
1382 const bool checkActiveViewer )
1384 SALOME_ListIteratorOfListIO Iter( theIOList );
1385 for ( ; Iter.More(); Iter.Next() )
1386 Redisplay( Iter.Value(), false, checkActiveViewer );
1392 //=================================================================
1394 * GEOM_Displayer::Redisplay
1395 * Calls Redisplay() method for each object in the given list
1397 //=================================================================
1398 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1399 const bool theUpdateViewer,
1400 SALOME_View* theViewFrame )
1402 SALOME_ListIteratorOfListIO anIter( theIOList );
1403 for ( ; anIter.More(); anIter.Next() )
1405 Redisplay( anIter.Value(), false, theViewFrame );
1408 if ( theUpdateViewer )
1414 //=================================================================
1416 * GEOM_Displayer::Update
1417 * Update OCC presentaion
1418 * [ Reimplemented from SALOME_Displayer ]
1420 //=================================================================
1421 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
1423 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
1424 SalomeApp_Study* study = getStudy();
1426 if ( !occPrs || myShape.IsNull() || !study )
1429 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1432 // specific processing for local coordinate system presentation
1435 TopoDS_Face aFace = TopoDS::Face( myShape );
1436 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1437 if ( !aPlane.IsNull() )
1439 gp_Ax3 aPos = aPlane->Pln().Position();
1440 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1442 Handle(GEOM_AISTrihedron) aTrh;
1444 if ( occPrs->IsNull() )
1446 // new presentation is being created
1447 aTrh = new GEOM_AISTrihedron( aPlc );
1448 occPrs->AddObject( aTrh );
1452 // presentation is being updated
1453 AIS_ListOfInteractive aList;
1454 occPrs->GetObjects( aList );
1455 AIS_ListIteratorOfListOfInteractive anIter( aList );
1456 for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
1457 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
1461 if ( !aTrh.IsNull() ) {
1462 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1464 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1465 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1467 aTrh->SetWidth( GetWidth() );
1469 if ( !myIO.IsNull() )
1471 aTrh->setIO( myIO );
1472 aTrh->SetOwner( myIO );
1474 aTrh->SetComponent( aPlc );
1475 aTrh->SetToUpdate();
1477 occPrs->SetToActivate( ToActivate() );
1483 // processing for usual geometry presentation
1486 // if presentation is empty we try to create new one
1487 if ( occPrs->IsNull() )
1489 // create presentation (specific for vectors)
1490 Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1491 : new GEOM_AISShape ( myShape, "" );
1493 if( myType == GEOM_FIELD_STEP )
1494 AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight );
1495 // update shape properties
1496 updateShapeProperties( AISShape, true );
1498 // add shape to the presentation
1499 occPrs->AddObject( AISShape );
1501 // In accordance with ToActivate() value object will be activated/deactivated
1502 // when it will be displayed
1503 occPrs->SetToActivate( ToActivate() );
1505 if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1506 // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1508 // create additional wireframe shape
1509 Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1510 aWirePrs->SetWidth(AISShape->Width());
1511 if ( !myIO.IsNull() ) {
1512 aWirePrs->setIO( myIO );
1513 aWirePrs->SetOwner( myIO );
1516 // add shape to the presentation
1517 occPrs->AddObject( aWirePrs );
1520 // if presentation is found -> set again shape for it
1523 AIS_ListOfInteractive IOList;
1524 occPrs->GetObjects( IOList );
1525 AIS_ListIteratorOfListOfInteractive Iter( IOList );
1526 for ( ; Iter.More(); Iter.Next() )
1528 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1529 if ( AISShape.IsNull() )
1532 // re-set shape (it might be changed)
1533 if ( AISShape->Shape() != myShape )
1534 AISShape->Set( myShape );
1536 // update shape properties
1537 updateShapeProperties( AISShape, false );
1540 AISShape->UpdateSelection();
1541 AISShape->SetToUpdate();
1545 updateDimensions( myIO, occPrs, gp_Ax3().Transformed( myShape.Location().Transformation() ) );
1549 //=================================================================
1551 * GEOM_Displayer::Update
1552 * Update VTK presentaion
1553 * [ Reimplemented from SALOME_Displayer ]
1555 //=================================================================
1556 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1558 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1559 SalomeApp_Study* study = getStudy();
1561 if ( !vtkPrs || myShape.IsNull() || !study )
1564 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1567 // specific processing for local coordinate system presentation
1570 TopoDS_Face aFace = TopoDS::Face( myShape );
1571 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1572 if ( !aPlane.IsNull() ) {
1573 gp_Ax3 aPos = aPlane->Pln().Position();
1574 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1576 GEOM_VTKTrihedron* aTrh = 0;
1578 if ( vtkPrs->IsNull() ) {
1579 // new presentation is being created
1580 aTrh = GEOM_VTKTrihedron::New();
1581 vtkPrs->AddObject( aTrh );
1584 // presentation is being updated
1585 vtkActorCollection* actors = vtkPrs->GetObjects();
1587 actors->InitTraversal();
1588 vtkActor* a = actors->GetNextActor();
1589 while ( a && !aTrh ) {
1590 aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1591 a = actors->GetNextActor();
1597 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1599 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1600 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1602 #ifdef VTK_TRIHEDRON_WIDTH
1604 // VSR: currently isn't supported
1606 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1608 aTrh->SetWidth( GetWidth() );
1611 if ( !myIO.IsNull() )
1612 aTrh->setIO( myIO );
1614 aTrh->SetPlacement( aPlc );
1621 // processing for usual geometry presentation
1624 // if presentation is empty we try to create new one
1625 if ( vtkPrs->IsNull() )
1628 GEOM_Actor* actor = GEOM_Actor::New();
1629 // update actor properties
1630 updateActorProperties( actor, true );
1631 // add actor to the presentation
1632 vtkPrs->AddObject( actor );
1635 // presentation is being updated
1636 vtkActorCollection* actors = vtkPrs->GetObjects();
1638 actors->InitTraversal();
1639 vtkActor* a = actors->GetNextActor();
1641 GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1643 // update actor properties
1644 updateActorProperties( actor, false );
1645 a = actors->GetNextActor();
1653 //=================================================================
1655 * GEOM_Displayer::BuildPrs
1656 * Build presentation accordint to the current viewer type
1658 //=================================================================
1659 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1661 if ( theObj->_is_nil() )
1664 myViewFrame = GetActiveView();
1665 if ( myViewFrame == 0 )
1668 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1673 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1674 myType = theObj->GetType();
1676 // Update presentation
1682 //=================================================================
1684 * GEOM_Displayer::BuildPrs
1685 * Build presentation accordint to the current viewer type
1687 //=================================================================
1688 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1690 myViewFrame = GetActiveView();
1691 if ( theShape.IsNull() || myViewFrame == 0 )
1694 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1699 setShape( theShape );
1707 //=================================================================
1709 * GEOM_Displayer::buildPresentation
1710 * Builds/finds object's presentation for the current viewer
1711 * Calls corresponding Update() method by means of double dispatch
1714 //=================================================================
1715 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1716 SALOME_View* theViewFrame )
1718 SALOME_Prs* prs = 0;
1721 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1725 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1728 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1729 theIO->setEntry( entry.toLatin1().constData() );
1730 if ( !theIO.IsNull() )
1732 // set interactive object
1734 // Find SOBject (because shape should be published previously)
1735 SUIT_Session* session = SUIT_Session::session();
1736 SUIT_Application* app = session->activeApplication();
1739 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1742 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1745 // get CORBA reference to data object
1746 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1747 if ( !CORBA::is_nil( object ) )
1749 // downcast to GEOM base object
1750 GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
1751 if ( !GeomBaseObject->_is_nil() )
1753 myType = GeomBaseObject->GetType();
1755 // downcast to GEOM object
1756 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
1757 if ( myType == GEOM_FIELD_STEP )
1759 // get the GEOM object from the field's shape
1760 GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
1761 if ( !GeomFieldStep->_is_nil() )
1763 GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
1764 if ( !GeomField->_is_nil() )
1765 GeomObject = GeomField->GetShape();
1768 // read the field step information
1769 readFieldStepInfo( GeomFieldStep );
1772 if ( !GeomObject->_is_nil() )
1774 theIO->setName( GeomObject->GetName() );
1775 // finally set shape
1776 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1784 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1790 //=================================================================
1792 * GEOM_Displayer::buildSubshapePresentation
1793 * Builds/finds object's presentation for the current viewer
1794 * Calls corresponding Update() method by means of double dispatch
1795 * For not published objects (for Mantis issue 0020435)
1797 //=================================================================
1798 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1799 const QString& entry,
1800 SALOME_View* theViewFrame)
1802 SALOME_Prs* prs = 0;
1805 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1809 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1812 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1813 theIO->setEntry(entry.toLatin1().constData());
1814 if (!theIO.IsNull())
1816 // set interactive object
1818 // finally set shape
1820 myType = GEOM_SUBSHAPE;
1822 UpdatePrs(prs); // Update presentation by using of the double dispatch
1828 //=================================================================
1830 * GEOM_Displayer::internalReset
1831 * Resets internal data
1834 //=================================================================
1835 void GEOM_Displayer::internalReset()
1840 myFieldDataType = GEOM::FDT_Double;
1841 myFieldDimension = 0;
1842 myFieldStepData.clear();
1843 myFieldStepName.Clear();
1844 myFieldStepRangeMin = 0;
1845 myFieldStepRangeMax = 0;
1848 //=================================================================
1850 * GEOM_Displayer::LocalSelection
1851 * Activate selection of CAD shapes with activisation of selection
1852 * of their sub-shapes (with opened local context for OCC viewer)
1854 //=================================================================
1855 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const std::list<int> modes )
1857 SUIT_Session* session = SUIT_Session::session();
1858 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1862 LightApp_SelectionMgr* sm = app->selectionMgr();
1864 // remove all filters from selection
1867 SALOME_View* vf = GetActiveView();
1869 if (!theIO.IsNull() && !vf->isVisible(theIO))
1871 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1872 vf->LocalSelection( prs, modes );
1873 delete prs; // delete presentation because displayer is its owner
1877 //=================================================================
1879 * GEOM_Displayer::LocalSelection
1880 * Activate selection of CAD shapes with activisation of selection
1881 * of their sub-shapes (with opened local context for OCC viewer)
1883 //=================================================================
1884 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1886 std::list<int> modes;
1887 modes.push_back( theMode );
1888 LocalSelection( theIO, modes );
1891 //=================================================================
1893 * GEOM_Displayer::globalSelection
1894 * Activate selection of CAD shapes without activisation of selection
1895 * of their sub-shapes (without opened local context for OCC viewer)
1897 //=================================================================
1898 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1900 TColStd_MapOfInteger aModes;
1901 aModes.Add( theMode );
1902 GlobalSelection( aModes, update );
1905 //=================================================================
1907 * GEOM_Displayer::globalSelection
1908 * Activate selection of CAD shapes without activisation of selection
1909 * of their sub-shapes (without opened local context for OCC viewer)
1911 //=================================================================
1912 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1913 const bool update, const QList<int>* theSubShapes )
1915 SUIT_Session* session = SUIT_Session::session();
1916 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1920 SALOME_View* vf = GetActiveView();
1924 // Close local context
1925 vf->GlobalSelection( update );
1927 // Set selection filters in accordance with current mode
1928 LightApp_SelectionMgr* sm = app->selectionMgr();
1932 // Remove from selection temporary objects if necessary
1933 if ( !theModes.Contains( GEOM_PREVIEW ) )
1934 clearTemporary( sm );
1936 //@ aSel->ClearIndex();
1940 // Remove filters from AIS_InteractiveContext
1941 Handle(AIS_InteractiveContext) ic;
1942 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1945 ic = viewer->getAISContext();
1947 ic->RemoveFilters();
1950 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1953 SUIT_SelectionFilter* aFilter;
1954 if ( theModes.Extent() == 1 )
1956 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1958 if ( aMode == GEOM_COMPOUNDFILTER )
1959 aFilter = getComplexFilter( theSubShapes );
1961 aFilter = getFilter( aMode );
1963 else if ( theModes.Extent() > 1 )
1965 TColStd_MapOfInteger aTopAbsModes;
1966 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1967 QList<SUIT_SelectionFilter*> aListOfFilters;
1968 for ( ; anIter.More(); anIter.Next() )
1970 SUIT_SelectionFilter* aFilter;
1971 int aMode = anIter.Key();
1972 if ( aMode == GEOM_COMPOUNDFILTER )
1973 aFilter = getComplexFilter( theSubShapes );
1975 aFilter = getFilter( aMode );
1978 aListOfFilters.append( aFilter );
1981 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1988 sm->installFilter( aFilter );
1991 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1992 ic->AddFilter( anOCCFilter );
1997 //=================================================================
1999 * GEOM_Displayer::LocalSelection
2000 * Activate selection of CAD shapes with activisation of selection
2001 * of their sub-shapes (with opened local context for OCC viewer)
2003 //=================================================================
2004 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const std::list<int> modes )
2006 SALOME_ListIteratorOfListIO Iter( theIOList );
2007 for ( ; Iter.More(); Iter.Next() )
2008 LocalSelection( Iter.Value(), modes );
2011 //=================================================================
2013 * GEOM_Displayer::LocalSelection
2014 * Activate selection of CAD shapes with activisation of selection
2015 * of their sub-shapes (with opened local context for OCC viewer)
2017 //=================================================================
2018 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
2020 std::list<int> modes;
2021 modes.push_back( theMode );
2022 LocalSelection( theIOList, modes );
2025 //=================================================================
2027 * GEOM_Displayer::BeforeDisplay
2028 * Called before displaying of pars. Close local context
2029 * [ Reimplemented from SALOME_Displayer ]
2031 //=================================================================
2032 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
2034 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
2037 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
2040 if ( ic->HasOpenedContext() )
2041 ic->CloseAllContexts();
2046 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
2048 UpdateColorScale(false,false);
2051 void GEOM_Displayer::BeforeErase( SALOME_View* v, const SALOME_OCCPrs* p )
2053 LightApp_Displayer::BeforeErase( v, p );
2054 releaseTextures( p );
2057 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
2059 LightApp_Displayer::AfterErase( v, p );
2060 UpdateColorScale(false,false);
2063 //=================================================================
2065 * GEOM_Displayer::SetColor
2066 * Set color for shape displaying. If it is equal -1 then default color is used.
2067 * Available values are from Quantity_NameOfColor enumeration
2069 //=================================================================
2070 void GEOM_Displayer::SetColor( const int color )
2077 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
2081 int GEOM_Displayer::GetColor() const
2086 bool GEOM_Displayer::HasColor() const
2088 return myColor != -1;
2091 void GEOM_Displayer::UnsetColor()
2095 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2096 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
2097 myShadingColor = SalomeApp_Tools::color( col );
2100 //=================================================================
2102 * GEOM_Displayer::SetTransparency
2103 * Set transparency for shape displaying.
2105 //=================================================================
2106 double GEOM_Displayer::SetTransparency( const double transparency )
2108 double prevTransparency = myTransparency;
2109 myTransparency = transparency;
2110 return prevTransparency;
2113 //=================================================================
2115 * GEOM_Displayer::GetTransparency
2116 * Get transparency for shape displaying.
2118 //=================================================================
2119 double GEOM_Displayer::GetTransparency() const
2121 return myTransparency;
2124 //=================================================================
2126 * GEOM_Displayer::HasTransparency
2127 * Check if transparency for shape displaying is set.
2129 //=================================================================
2130 bool GEOM_Displayer::HasTransparency() const
2132 return myTransparency >= 0;
2135 //=================================================================
2137 * GEOM_Displayer::UnsetTransparency
2138 * Unset transparency for shape displaying.
2140 //=================================================================
2141 double GEOM_Displayer::UnsetTransparency()
2143 return SetTransparency( -1 );
2146 //=================================================================
2148 * GEOM_Displayer::SetTexture
2150 //=================================================================
2151 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
2153 myTexture = texureFileName;
2156 bool GEOM_Displayer::HasTexture() const
2158 return myTexture != "";
2161 std::string GEOM_Displayer::GetTexture() const
2166 //=================================================================
2168 * GEOM_Displayer::SetWidth
2169 * Set width of shape displaying. If it is equal -1 then default width is used.
2171 //=================================================================
2172 void GEOM_Displayer::SetWidth( const double width )
2177 double GEOM_Displayer::GetWidth() const
2182 bool GEOM_Displayer::HasWidth() const
2184 return myWidth != -1;
2187 void GEOM_Displayer::UnsetWidth()
2192 int GEOM_Displayer::GetIsosWidth() const
2197 void GEOM_Displayer::SetIsosWidth(const int width)
2199 myIsosWidth = width;
2202 bool GEOM_Displayer::HasIsosWidth() const
2204 return myIsosWidth != -1;
2207 int GEOM_Displayer::SetNbIsos( const int nbIsos )
2209 int prevNbIsos = myNbIsos;
2214 int GEOM_Displayer::UnsetNbIsos()
2216 return SetNbIsos( -1 );
2219 int GEOM_Displayer::GetNbIsos() const
2224 bool GEOM_Displayer::HasNbIsos() const
2226 return myNbIsos >= 0;
2229 int GEOM_Displayer::SetIsosColor( const int color )
2231 int prevColor = myIsosColor;
2232 myIsosColor = color;
2236 int GEOM_Displayer::GetIsosColor() const
2241 bool GEOM_Displayer::HasIsosColor() const
2243 return myIsosColor != -1;
2246 int GEOM_Displayer::UnsetIsosColor()
2248 return SetIsosColor( -1 );
2251 //=================================================================
2253 * GEOM_Displayer::SetToActivate
2254 * This method is used for activisation/deactivisation of objects to be displayed
2256 //=================================================================
2257 void GEOM_Displayer::SetToActivate( const bool toActivate )
2259 myToActivate = toActivate;
2261 bool GEOM_Displayer::ToActivate() const
2263 return myToActivate;
2266 //=================================================================
2268 * GEOM_Displayer::clearTemporary
2269 * Removes from selection temporary objects
2271 //=================================================================
2272 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
2274 SALOME_ListIO selected, toSelect;
2275 theSelMgr->selectedObjects( selected );
2277 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
2278 Handle(SALOME_InteractiveObject) io = it.Value();
2279 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
2280 toSelect.Append( it.Value() );
2283 theSelMgr->setSelectedObjects( toSelect, true );
2286 void GEOM_Displayer::SetName( const char* theName )
2291 void GEOM_Displayer::UnsetName()
2296 SalomeApp_Study* GEOM_Displayer::getStudy() const
2298 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2301 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
2306 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
2311 void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
2312 const int theFieldDimension,
2313 const QList<QVariant>& theFieldStepData,
2314 const TCollection_AsciiString& theFieldStepName,
2315 const double theFieldStepRangeMin,
2316 const double theFieldStepRangeMax )
2318 myFieldDataType = theFieldDataType;
2319 myFieldDimension = theFieldDimension;
2320 myFieldStepData = theFieldStepData;
2321 myFieldStepName = theFieldStepName;
2322 myFieldStepRangeMin = theFieldStepRangeMin;
2323 myFieldStepRangeMax = theFieldStepRangeMax;
2326 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
2328 _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
2329 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
2330 GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
2331 GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
2332 return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
2333 (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
2336 int GEOM_Displayer::SetDisplayMode( const int theMode )
2338 int aPrevMode = myDisplayMode;
2339 if ( theMode != -1 ) {
2340 myDisplayMode = theMode;
2341 myHasDisplayMode = true;
2349 int GEOM_Displayer::GetDisplayMode() const
2351 return myDisplayMode;
2354 int GEOM_Displayer::UnsetDisplayMode()
2356 int aPrevMode = myDisplayMode;
2357 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2358 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
2359 myHasDisplayMode = false;
2363 bool GEOM_Displayer::HasDisplayMode() const
2365 return myHasDisplayMode;
2368 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
2370 static QList<QColor> colors;
2372 if ( colors.isEmpty() ) {
2374 for (int s = 0; s < 2 ; s++)
2376 for (int v = 100; v >= 40; v = v - 20)
2378 for (int h = 0; h < 359 ; h = h + 60)
2380 colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
2386 static int currentColor = randomize( colors.size() );
2388 SALOMEDS::Color color;
2389 color.R = (double)colors[currentColor].red() / 255.0;
2390 color.G = (double)colors[currentColor].green() / 255.0;
2391 color.B = (double)colors[currentColor].blue() / 255.0;
2393 currentColor = (currentColor+1) % colors.count();
2398 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
2401 int aTolerance = 64;
2402 int anIterations = 0;
2408 if( anIterations % aPeriod == 0 )
2411 if( aTolerance < 1 )
2414 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
2416 aHue = (int)( 360.0 * rand() / RAND_MAX );
2417 //std::cout << "Hue = " << aHue << std::endl;
2419 //std::cout << "Auto colors : ";
2421 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
2422 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
2423 for( ; it != itEnd; ++it )
2425 SALOMEDS::Color anAutoColor = *it;
2426 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
2429 aQColor.getHsv( &h, &s, &v );
2430 //std::cout << h << " ";
2431 if( abs( h - aHue ) < aTolerance )
2434 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
2438 //std::cout << std::endl;
2444 //std::cout << "Hue of the returned color = " << aHue << std::endl;
2446 aColor.setHsv( aHue, 255, 255 );
2448 SALOMEDS::Color aSColor;
2449 aSColor.R = (double)aColor.red() / 255.0;
2450 aSColor.G = (double)aColor.green() / 255.0;
2451 aSColor.B = (double)aColor.blue() / 255.0;
2456 PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
2457 const QString& entry,
2460 // get default properties for the explicitly specified default view type
2461 PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
2463 if ( study && view ) {
2464 SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
2465 SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
2466 int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
2468 if ( viewModel && viewId != -1 ) {
2469 // get properties from the study
2470 PropMap storedMap = study->getObjectProperties( viewId, entry );
2471 // overwrite default properties from stored ones (that are specified)
2472 for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
2473 if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
2474 propMap.insert( GEOM::propertyName( (GEOM::Property)prop ),
2475 storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
2477 // ... specific processing for color
2478 // ... current implementation is to use same stored color for all aspects
2479 // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2480 if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2481 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2482 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2483 propMap.insert( GEOM::propertyName( GEOM::LineColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2484 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2485 propMap.insert( GEOM::propertyName( GEOM::PointColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2488 if ( !entry.isEmpty() ) {
2489 // get CORBA reference to geom object
2490 _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
2492 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
2493 if ( !CORBA::is_nil( object ) ) {
2494 GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
2495 if ( !CORBA::is_nil( geomObject ) ) { // to check
2496 // check that geom object has color properly set
2497 bool hasColor = false;
2498 SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
2499 // set color from geometry object (only once, if it is not yet set in GUI)
2500 // current implementation is to use same color for all aspects
2501 // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2502 if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2503 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
2504 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), objColor );
2505 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
2506 propMap.insert( GEOM::propertyName( GEOM::LineColor ), objColor );
2507 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), objColor );
2508 propMap.insert( GEOM::propertyName( GEOM::PointColor ), objColor );
2510 // check that object has point marker properly set
2511 GEOM::marker_type mType = geomObject->GetMarkerType();
2512 GEOM::marker_size mSize = geomObject->GetMarkerSize();
2513 int mTextureId = geomObject->GetMarkerTexture();
2514 bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) ||
2515 ( mType == GEOM::MT_USER && mTextureId > 0 );
2516 // set point marker from geometry object (only once, if it is not yet set in GUI)
2517 if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
2518 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
2520 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2521 QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
2523 else if ( mType == GEOM::MT_USER ) {
2525 propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
2537 PropMap GEOM_Displayer::getDefaultPropertyMap()
2541 // get resource manager
2542 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2544 // fill in the properties map with default values
2546 // - visibility (false by default)
2547 propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
2549 // - nb isos (take default value from preferences)
2550 propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
2551 QString( "%1%2%3" ).
2552 arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
2553 arg( GEOM::subSectionSeparator() ).
2554 arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
2556 // - transparency (opacity = 1-transparency)
2557 propMap.insert( GEOM::propertyName( GEOM::Transparency ),
2558 resMgr->integerValue( "Geometry", "transparency", 0 ) / 100. );
2560 // - display mode (take default value from preferences)
2561 propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
2562 resMgr->integerValue( "Geometry", "display_mode", 0 ) );
2564 // - show edges direction flag (false by default)
2565 propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
2567 // - show vertices flag (false by default)
2568 propMap.insert( GEOM::propertyName( GEOM::Vertices ), false );
2570 // - show name flag (false by default)
2571 propMap.insert( GEOM::propertyName( GEOM::ShowName ), false );
2573 // - shading color (take default value from preferences)
2574 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
2575 colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
2577 // - wireframe color (take default value from preferences)
2578 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
2579 colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
2581 // - standalone edges color (take default value from preferences)
2582 propMap.insert( GEOM::propertyName( GEOM::LineColor ),
2583 colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
2585 // - free boundaries color (take default value from preferences)
2586 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
2587 colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
2589 // - points color (take default value from preferences)
2590 propMap.insert( GEOM::propertyName( GEOM::PointColor ),
2591 colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
2593 // - isos color (take default value from preferences)
2594 propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
2595 colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
2597 // - outlines color (take default value from preferences)
2598 propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
2599 colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
2601 // - deflection coefficient (take default value from preferences)
2602 propMap.insert( GEOM::propertyName( GEOM::Deflection ),
2603 resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
2605 // - material (take default value from preferences)
2606 Material_Model material;
2607 material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
2608 propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
2610 // - edge width (take default value from preferences)
2611 propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
2612 resMgr->integerValue( "Geometry", "edge_width", 1 ) );
2614 // - isos width (take default value from preferences)
2615 propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
2616 resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
2618 // - point marker (take default value from preferences)
2619 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2620 QString( "%1%2%3" ).
2621 arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
2622 arg( GEOM::subSectionSeparator() ).
2623 arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2625 // - top-level flag (false by default)
2626 propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2631 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2632 SALOMEDS::Color aSColor;
2635 SUIT_Session* session = SUIT_Session::session();
2636 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2638 if ( app && !theGeomObject->_is_nil()) {
2639 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2642 _PTR(Study) aStudy = study->studyDS();
2643 aSColor = theGeomObject->GetColor();
2644 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2646 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2647 bool general_autocolor = true;
2648 #else // auto-color for groups only
2649 bool general_autocolor = false;
2650 #endif // GENERAL_AUTOCOLOR
2651 if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2652 GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2653 if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2654 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2655 aSColor = getPredefinedUniqueColor();
2657 #else // old algorithm for auto-colors
2658 QList<SALOMEDS::Color> aReservedColors;
2659 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2660 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2661 if ( aMainSObject ) {
2662 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2663 for ( ; it->More(); it->Next() ) {
2664 _PTR(SObject) aChildSObject( it->Value() );
2665 GEOM::GEOM_Object_var aChildObject =
2666 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2667 if ( CORBA::is_nil( aChildObject ) )
2670 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2671 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2672 aReservedColors.append( aReservedColor );
2675 aSColor = getUniqueColor( aReservedColors );
2677 #endif // SIMPLE_AUTOCOLOR
2687 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2688 const bool eraseOnlyChildren) {
2689 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2693 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2697 LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2702 // Erase from all views
2703 QList<SALOME_View*> views;
2705 ViewManagerList vmans = app->viewManagers();
2706 SUIT_ViewManager* vman;
2707 foreach ( vman, vmans ) {
2708 SUIT_ViewModel* vmod = vman->getViewModel();
2709 view = dynamic_cast<SALOME_View*> ( vmod );
2711 views.append( view );
2714 if( views.count() == 0 )
2717 //Erase childrens w/o update views
2718 DataObjectList listObj = parent->children( true );
2719 SUIT_DataObject* obj;
2720 foreach( obj, listObj ) {
2721 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2723 foreach ( view, views ) {
2724 Handle(SALOME_InteractiveObject) anIO =
2725 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2726 Erase(anIO, false, false, view);
2730 //Erase parent with view update or repaint views
2731 foreach ( view, views ) {
2732 if(!eraseOnlyChildren)
2733 Erase(theIO, false, true, view);
2739 void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
2741 if( theGeomFieldStep->_is_nil() )
2744 GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
2745 if( aGeomField->_is_nil() )
2748 GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
2749 if( aGeomFieldShape->_is_nil() )
2752 TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
2753 TCollection_AsciiString aFieldName( aGeomField->GetName() );
2754 TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
2756 aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
2758 GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
2760 int aFieldDimension = aGeomField->GetDimension();
2762 GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
2763 int aFieldNbComponents = aFieldComponents->length();
2765 QList<QVariant> aFieldStepData;
2766 if( aFieldDataType == GEOM::FDT_Bool )
2768 GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
2769 if ( !aGeomBoolFieldStep->_is_nil() )
2771 GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
2772 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2773 aFieldStepData << (bool)aValues[i];
2776 else if( aFieldDataType == GEOM::FDT_Int )
2778 GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
2779 if ( !aGeomIntFieldStep->_is_nil() )
2781 GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
2782 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2783 aFieldStepData << (qlonglong)aValues[i];
2786 else if( aFieldDataType == GEOM::FDT_Double )
2788 GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
2789 if ( !aGeomDoubleFieldStep->_is_nil() )
2791 GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
2792 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2793 aFieldStepData << (double)aValues[i];
2796 else if( aFieldDataType == GEOM::FDT_String )
2798 GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
2799 if ( !aGeomStringFieldStep->_is_nil() )
2801 GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
2802 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2803 aFieldStepData << QString( aValues[i] );
2807 double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
2808 aFieldStepData = groupFieldData( aFieldStepData,
2810 aFieldDataType == GEOM::FDT_String,
2812 aFieldStepRangeMax );
2814 setFieldStepInfo( aFieldDataType,
2819 aFieldStepRangeMax );
2822 QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
2823 const int theFieldNbComponents,
2824 const bool theIsString,
2825 double& theFieldStepRangeMin,
2826 double& theFieldStepRangeMax )
2828 QList<QVariant> aResultList;
2829 theFieldStepRangeMin = 0;
2830 theFieldStepRangeMax = 0;
2832 if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
2835 int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
2837 QList<QVariant> aGroupedList;
2839 bool anIsBoolean = false;
2840 for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
2843 QStringList aStringList;
2845 int aBaseIndex = aSubShape * theFieldNbComponents;
2846 for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
2848 int anIndex = aComponent + aBaseIndex;
2850 const QVariant& aVariant = theFieldStepData[ anIndex ];
2853 if( aVariant.type() == QVariant::String )
2854 aStringList << aVariant.toString();
2859 if( aVariant.type() == QVariant::Bool )
2861 aValue = aVariant.toBool() ? 1.0 : 0.0;
2867 if( aVariant.type() == QVariant::LongLong )
2868 aValue = double( aVariant.toLongLong() );
2869 else if( aVariant.type() == QVariant::Double )
2870 aValue = aVariant.toDouble();
2871 aNorm += aValue * aValue;
2877 aGroupedList << aStringList.join( "\n" );
2881 aNorm /= theFieldNbComponents;
2883 aNorm = pow( aNorm, 0.5 );
2885 if( aGroupedList.isEmpty() )
2886 theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
2889 theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
2890 theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
2893 aGroupedList << aNorm;
2899 theFieldStepRangeMin = 0.0;
2900 theFieldStepRangeMax = 1.0;
2903 SUIT_Session* session = SUIT_Session::session();
2904 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2905 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2907 QListIterator<QVariant> anIter( aGroupedList );
2908 while( anIter.hasNext() )
2910 const QVariant& aVariant = anIter.next();
2912 aResultList << aVariant;
2916 Quantity_Color aColor;
2917 if( FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2918 aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
2919 aResultList << aQColor;
2925 // Note: the method is copied from Aspect_ColorScale class
2926 Standard_Integer GEOM_Displayer::HueFromValue( const Standard_Integer aValue,
2927 const Standard_Integer aMin,
2928 const Standard_Integer aMax )
2930 Standard_Integer minLimit( 0 ), maxLimit( 230 );
2932 Standard_Integer aHue = maxLimit;
2934 aHue = (Standard_Integer)( maxLimit - ( maxLimit - minLimit ) * ( aValue - aMin ) / ( aMax - aMin ) );
2936 aHue = Min( Max( minLimit, aHue ), maxLimit );
2941 // Note: the method is copied from Aspect_ColorScale class
2942 Standard_Boolean GEOM_Displayer::FindColor( const Standard_Real aValue,
2943 const Standard_Real aMin,
2944 const Standard_Real aMax,
2945 const Standard_Integer ColorsCount,
2946 Quantity_Color& aColor )
2948 if( aValue<aMin || aValue>aMax || aMax<aMin )
2949 return Standard_False;
2953 Standard_Real IntervNumber = 0;
2956 else if( aValue>aMax )
2957 IntervNumber = ColorsCount-1;
2958 else if( Abs( aMax-aMin ) > Precision::Approximation() )
2959 IntervNumber = Floor( Standard_Real( ColorsCount ) * ( aValue - aMin ) / ( aMax - aMin ) ); // 'Ceiling' replaced with 'Floor'
2961 Standard_Integer Interv = Standard_Integer( IntervNumber );
2963 aColor = Quantity_Color( HueFromValue( Interv, 0, ColorsCount - 1 ), 1.0, 1.0, Quantity_TOC_HLS );
2965 return Standard_True;
2969 void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, const bool updateViewer )
2971 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2975 SOCC_Viewer* aViewModel = dynamic_cast<SOCC_Viewer*>( GetActiveView() );
2979 Handle(V3d_Viewer) aViewer = aViewModel->getViewer3d();
2980 if( aViewer.IsNull() )
2983 aViewer->InitActiveViews();
2984 if( !aViewer->MoreActiveViews() )
2987 Handle(V3d_View) aView = aViewer->ActiveView();
2988 if( aView.IsNull() )
2991 Standard_Boolean anIsDisplayColorScale = Standard_False;
2992 TCollection_AsciiString aColorScaleTitle;
2993 Standard_Real aColorScaleMin = 0, aColorScaleMax = 0;
2994 Standard_Boolean anIsBoolean = Standard_False;
2996 SALOME_ListIO aSelectedObjects;
2997 myApp->selectionMgr()->selectedObjects( aSelectedObjects );
2998 if( aSelectedObjects.Extent() == 1 )
3000 Handle(SALOME_InteractiveObject) anIO = aSelectedObjects.First();
3001 if( !anIO.IsNull() )
3003 SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( aViewModel->CreatePrs( anIO->getEntry() ) );
3006 AIS_ListOfInteractive aList;
3007 aPrs->GetObjects( aList );
3008 AIS_ListIteratorOfListOfInteractive anIter( aList );
3009 for( ; anIter.More(); anIter.Next() )
3011 Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() );
3012 if( !aShape.IsNull() )
3014 GEOM::field_data_type aFieldDataType;
3015 int aFieldDimension;
3016 QList<QVariant> aFieldStepData;
3017 TCollection_AsciiString aFieldStepName;
3018 double aFieldStepRangeMin, aFieldStepRangeMax;
3019 aShape->getFieldStepInfo( aFieldDataType,
3024 aFieldStepRangeMax );
3025 if( !aFieldStepData.isEmpty() && aFieldDataType != GEOM::FDT_String )
3027 anIsDisplayColorScale = Standard_True;
3028 aColorScaleTitle = aFieldStepName;
3029 aColorScaleMin = aFieldStepRangeMin;
3030 aColorScaleMax = aFieldStepRangeMax;
3031 anIsBoolean = aFieldDataType == GEOM::FDT_Bool;
3039 if( anIsDisplayColorScale )
3041 Handle(Aspect_ColorScale) aColorScale = aView->ColorScale();
3042 if( !aColorScale.IsNull() )
3044 SUIT_Session* session = SUIT_Session::session();
3045 SUIT_ResourceMgr* resMgr = session->resourceMgr();
3047 Standard_Real anXPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
3048 Standard_Real anYPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
3049 Standard_Real aWidth = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
3050 Standard_Real aHeight = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
3051 Standard_Integer aTextHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
3052 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
3054 aColorScale->SetXPosition( anXPos );
3055 aColorScale->SetYPosition( anYPos );
3056 aColorScale->SetWidth( aWidth );
3057 aColorScale->SetHeight( aHeight );
3059 aColorScale->SetTextHeight( aTextHeight );
3060 aColorScale->SetNumberOfIntervals( anIsBoolean ? 2 : aNbIntervals );
3062 aColorScale->SetTitle( aColorScaleTitle );
3063 aColorScale->SetRange( aColorScaleMin, aColorScaleMax );
3065 if( !aView->ColorScaleIsDisplayed() )
3066 aView->ColorScaleDisplay();
3070 if( aView->ColorScaleIsDisplayed() )
3071 aView->ColorScaleErase();
3074 if( theIsRedisplayFieldSteps )
3076 _PTR(Study) aStudyDS = aStudy->studyDS();
3077 QList<SUIT_ViewManager*> vmList;
3078 myApp->viewManagers( vmList );
3079 for( QList<SUIT_ViewManager*>::Iterator vmIt = vmList.begin(); vmIt != vmList.end(); vmIt++ )
3081 if( SUIT_ViewManager* aViewManager = *vmIt )
3083 const ObjMap& anObjects = aStudy->getObjectProperties( aViewManager->getGlobalId() );
3084 for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ )
3086 _PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) );
3089 CORBA::Object_var anObject = GeometryGUI::ClientSObjectToObject( aSObj );
3090 if( !CORBA::is_nil( anObject ) )
3092 GEOM::GEOM_FieldStep_var aFieldStep = GEOM::GEOM_FieldStep::_narrow( anObject );
3093 if( !aFieldStep->_is_nil() )
3095 CORBA::String_var aStepEntry = aFieldStep->GetStudyEntry();
3096 Handle(SALOME_InteractiveObject) aStepIO =
3097 new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" );
3098 Redisplay( aStepIO, false, false );