X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGEOMGUI%2FGEOM_Displayer.cxx;h=82853c712ff04441591de18bf7fd9352b4790a13;hb=22b9c99081495ff0b7c053b9b7e779b105a73044;hp=e13cba929e188f2da6de86d914c928f8353cc722;hpb=6fa64130e586f57e807bfb298c52f10bfb2c0b2d;p=modules%2Fgeom.git diff --git a/src/GEOMGUI/GEOM_Displayer.cxx b/src/GEOMGUI/GEOM_Displayer.cxx index e13cba929..82853c712 100644 --- a/src/GEOMGUI/GEOM_Displayer.cxx +++ b/src/GEOMGUI/GEOM_Displayer.cxx @@ -1,6 +1,6 @@ -// GEOM GEOMGUI : GUI for Geometry component +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE // -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // // This library is free software; you can redistribute it and/or @@ -17,37 +17,37 @@ // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// -// -// File : GEOM_Displayer.cxx -// Author : Vadim SANDLER -// Module : GEOM -// $Header$ +// GEOM GEOMGUI : GUI for Geometry component +// File : GEOM_Displayer.cxx +// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) +// #include "GEOM_Displayer.h" #include "GeometryGUI.h" -#include "GEOM_TypeFilter.h" -#include "GEOM_EdgeFilter.h" -#include "GEOM_FaceFilter.h" -#include "GEOM_PreviewFilter.h" -#include "GEOM_LogicalFilter.h" -#include "GEOM_OCCFilter.h" - -#include "GEOM_Actor.h" -#include "GEOM_AssemblyBuilder.h" -#include "GEOM_AISShape.hxx" -#include "GEOM_AISTrihedron.hxx" -#include "GEOM_VTKTrihedron.hxx" +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include #include #include #include -#include #include +#include #include #include @@ -56,6 +56,8 @@ #include #include +#include +#include #include #include @@ -63,14 +65,11 @@ #include #include -#include -#include - // OCCT Includes #include #include +#include #include -#include #include #include #include @@ -80,19 +79,19 @@ #include #include #include +#include +#include // VTK Includes #include - -// STL Includes -#include +#include // CORBA Headers #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes) -#include "GEOMImpl_Types.hxx" +#include +#include -using namespace std; //================================================================ // Function : getActiveStudy @@ -163,23 +162,47 @@ SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode ) return aFilter; } +//================================================================ +// Function : getComplexFilter +// Purpose : Get compound filter corresponding to the type of +// object from GEOMImpl_Types.h +//================================================================ +SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList* aSubShapes) +{ + GEOM_CompoundFilter* aFilter; + + if(aSubShapes != NULL ) { + aFilter = new GEOM_CompoundFilter(getStudy()); + QList aTopAbsTypes; + QList::const_iterator it; + for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) { + int topAbsMode = getTopAbsMode(*it); + if(topAbsMode != -1 ) + aTopAbsTypes.append(topAbsMode); + } + aFilter->addSubTypes(aTopAbsTypes); + } + + return aFilter; +} + //================================================================ // Function : getEntry // Purpose : //================================================================ -static string getEntry( GEOM::GEOM_Object_ptr object ) +static std::string getEntry( GEOM::GEOM_Object_ptr object ) { SUIT_Session* session = SUIT_Session::session(); SalomeApp_Application* app = dynamic_cast( session->activeApplication() ); if ( app ) { - string IOR = app->orb()->object_to_string( object ); - if ( IOR != "" ) + CORBA::String_var IOR = app->orb()->object_to_string( object ); + if ( strcmp(IOR.in(), "") != 0 ) { SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy(); - _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) ); + _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) ); if ( SO ) - return SO->GetID(); + return SO->GetID(); } } return ""; @@ -189,17 +212,17 @@ static string getEntry( GEOM::GEOM_Object_ptr object ) // Function : getName // Purpose : //================================================================ -static string getName( GEOM::GEOM_Object_ptr object ) +static std::string getName( GEOM::GEOM_Object_ptr object ) { SUIT_Session* session = SUIT_Session::session(); SalomeApp_Application* app = dynamic_cast( session->activeApplication() ); if ( app ) { - string IOR = app->orb()->object_to_string( object ); - if ( IOR != "" ) + CORBA::String_var IOR = app->orb()->object_to_string( object ); + if ( strcmp(IOR.in(), "") != 0 ) { SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy(); - _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( IOR ) ); + _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) ); _PTR(GenericAttribute) anAttr; @@ -220,9 +243,12 @@ static string getName( GEOM::GEOM_Object_ptr object ) * Constructor */ //================================================================= -GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* study ) +GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st ) { - myStudy = study; + if( st ) + myApp = dynamic_cast( st->application() ); + else + myApp = 0; /* Shading Color */ SUIT_Session* session = SUIT_Session::session(); @@ -232,6 +258,10 @@ GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* study ) myShadingColor = SalomeApp_Tools::color( col ); myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0); + int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS); + myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType))); + myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0; + myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker)); myColor = -1; // This color is used for shape displaying. If it is equal -1 then @@ -263,8 +293,8 @@ GEOM_Displayer::~GEOM_Displayer() */ //================================================================= void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO, - const bool updateViewer, - SALOME_View* theViewFrame ) + const bool updateViewer, + SALOME_View* theViewFrame ) { SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView(); if ( vf ) @@ -297,7 +327,7 @@ void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateVie if ( theObj->_is_nil() ) return; - string entry = getEntry( theObj ); + std::string entry = getEntry( theObj ); if ( entry != "" ) { Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()), updateViewer); @@ -313,7 +343,7 @@ void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateVie void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO, const bool forced, const bool updateViewer, - SALOME_View* theViewFrame ) + SALOME_View* theViewFrame ) { if ( theIO.IsNull() ) return; @@ -325,7 +355,7 @@ void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO, if ( prs ) { vf->Erase( prs, forced ); if ( updateViewer ) - vf->Repaint(); + vf->Repaint(); delete prs; // delete presentation because displayer is its owner } } @@ -341,7 +371,7 @@ void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj, const bool forced, const bool updateViewer ) { - string entry = getEntry( theObj ); + std::string entry = getEntry( theObj ); if ( entry != "" ) { Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()), @@ -365,26 +395,27 @@ void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO, if ( app ) { SUIT_Desktop* desk = app->desktop(); - QPtrList wnds = desk->windows(); + QList wnds = desk->windows(); SUIT_ViewWindow* wnd; - for ( wnd = wnds.first(); wnd; wnd = wnds.next() ) + QListIterator it( wnds ); + while ( it.hasNext() && (wnd = it.next()) ) { SUIT_ViewManager* vman = wnd->getViewManager(); if ( vman ) { - SUIT_ViewModel* vmodel = vman->getViewModel(); - if ( vmodel ) - { - SALOME_View* view = dynamic_cast(vmodel); - if ( view ) - { - if ( view->isVisible( theIO ) || view == GetActiveView() ) - { - Erase( theIO, true, false, view ); - Display( theIO, updateViewer, view ); - } - } - } + SUIT_ViewModel* vmodel = vman->getViewModel(); + if ( vmodel ) + { + SALOME_View* view = dynamic_cast(vmodel); + if ( view ) + { + if ( view->isVisible( theIO ) || view == GetActiveView() ) + { + Erase( theIO, true, false, view ); + Display( theIO, updateViewer, view ); + } + } + } } } } @@ -508,23 +539,106 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs ) { if ( !myShape.IsNull() ) { - Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" ); + //Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" ); + Handle(GEOM_AISShape) AISShape; + if (myType == GEOM_VECTOR) + AISShape = new GEOM_AISVector (myShape, ""); + else { + if (myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points + !TopoDS_Iterator(myShape).More()) + return;// NPAL15983 (Bug when displaying empty groups) + AISShape = new GEOM_AISShape (myShape, ""); + } // Temporary staff: vertex must be infinite for correct visualization - AISShape->SetInfiniteState( myShape.Infinite() || myShape.ShapeType() == TopAbs_VERTEX ); + AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines) // Setup shape properties here ..., e.g. display mode, color, transparency, etc - AISShape->SetDisplayMode( myDisplayMode ); + AISShape->SetDisplayMode( myDisplayMode ); AISShape->SetShadingColor( myShadingColor ); + // Set color and number for iso lines + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + QColor col = aResMgr->colorValue( "Geometry", "isos_color", + QColor(int(0.5*255), int(0.5*255), int(0.5*255)) ); + Quantity_Color aColor = SalomeApp_Tools::color( col ); + int anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1); + int aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1); + + Handle(Prs3d_IsoAspect) anAspect = AISShape->Attributes()->UIsoAspect(); + anAspect->SetNumber( anUIsoNumber ); + anAspect->SetColor( aColor ); + AISShape->Attributes()->SetUIsoAspect( anAspect ); + + anAspect = AISShape->Attributes()->VIsoAspect(); + anAspect->SetNumber( aVIsoNumber ); + anAspect->SetColor( aColor ); + AISShape->Attributes()->SetVIsoAspect( anAspect ); + if ( HasColor() ) { - AISShape->SetColor( (Quantity_NameOfColor)GetColor() ); + AISShape->SetColor( (Quantity_NameOfColor)GetColor() ); + Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect(); + anAspect->SetColor( (Quantity_NameOfColor)GetColor() ); + if ( myShape.ShapeType() == TopAbs_VERTEX ) + { + anAspect->SetScale( myScaleOfMarker ); + anAspect->SetTypeOfMarker( myTypeOfMarker ); + } + AISShape->Attributes()->SetPointAspect( anAspect ); + } + else + { if ( myShape.ShapeType() == TopAbs_VERTEX ) { + col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ); + aColor = SalomeApp_Tools::color( col ); + Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect(); - anAspect->SetColor( (Quantity_NameOfColor)GetColor() ); + anAspect->SetColor( aColor ); + anAspect->SetScale( myScaleOfMarker ); + anAspect->SetTypeOfMarker( myTypeOfMarker ); AISShape->Attributes()->SetPointAspect( anAspect ); } + else + { + // Set line aspect + col = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) ); + aColor = SalomeApp_Tools::color( col ); + + Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect(); + anAspect->SetColor( aColor ); + AISShape->Attributes()->SetLineAspect( anAspect ); + + // Set unfree boundaries aspect + anAspect = AISShape->Attributes()->UnFreeBoundaryAspect(); + anAspect->SetColor( aColor ); + AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect ); + + // Set free boundaries aspect + col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) ); + aColor = SalomeApp_Tools::color( col ); + + anAspect = AISShape->Attributes()->FreeBoundaryAspect(); + anAspect->SetColor( aColor ); + AISShape->Attributes()->SetFreeBoundaryAspect( anAspect ); + + // Set wire aspect + col = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) ); + aColor = SalomeApp_Tools::color( col ); + + anAspect = AISShape->Attributes()->WireAspect(); + anAspect->SetColor( aColor ); + AISShape->Attributes()->SetWireAspect( anAspect ); + + // bug [SALOME platform 0019868] + // Set deviation angle. Default one is 12 degrees (Prs3d_Drawer.cxx:18) + //AISShape->SetOwnDeviationAngle( 10*PI/180 ); + + // IMP 0020626 + double aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001); + aDC = std::max( aDC, DEFLECTION_MIN ); // to avoid to small values of the coefficient + AISShape->SetOwnDeviationCoefficient(aDC); + } } if ( HasWidth() ) @@ -546,6 +660,118 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs ) AISShape->setIO( anObj ); AISShape->SetOwner( anObj ); } + + // Get color and other properties from GEOM_Object + SUIT_Session* session = SUIT_Session::session(); + SUIT_Application* app = session->activeApplication(); + if ( app ) + { + SalomeApp_Study* study = dynamic_cast( app->activeStudy() ); + if ( study ) + { + Handle( SALOME_InteractiveObject ) anIO = AISShape->getIO(); + if ( !anIO.IsNull() ) + { + _PTR(SObject) SO ( study->studyDS()->FindObjectID( anIO->getEntry() ) ); + if ( SO ) + { + // get CORBA reference to data object + CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO); + if ( !CORBA::is_nil( object ) ) + { + // downcast to GEOM object + GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object ); + if ( !aGeomObject->_is_nil() ) + { + SALOMEDS::Color aSColor = aGeomObject->GetColor(); + bool hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0; + if( !hasColor && aGeomObject->GetType() == GEOM_GROUP ) // auto color for group + { + GEOM::GEOM_Gen_var aGeomGen = GeometryGUI::GetGeomGen(); + GEOM::GEOM_IGroupOperations_var anOperations = aGeomGen->GetIGroupOperations( study->id() ); + GEOM::GEOM_Object_var aMainObject = anOperations->GetMainShape( aGeomObject ); + if ( !aMainObject->_is_nil() && aMainObject->GetAutoColor() ) + { + QList aReservedColors; + + SalomeApp_Application* app = dynamic_cast( app ); + CORBA::String_var IOR = app->orb()->object_to_string( aMainObject ); + if ( strcmp(IOR.in(), "") != 0 ) + { + _PTR(Study) aStudy = study->studyDS(); + _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( std::string(IOR) ) ); + _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) ); + for( ; it->More(); it->Next() ) + { + _PTR(SObject) aChildSObject( it->Value() ); + GEOM::GEOM_Object_var aChildObject = + GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject)); + if( CORBA::is_nil( aChildObject ) ) + continue; + + if( aChildObject->GetType() != GEOM_GROUP ) + continue; + + SALOMEDS::Color aReservedColor = aChildObject->GetColor(); + aReservedColors.append( aReservedColor ); + } + } + + aSColor = getUniqueColor( aReservedColors ); + hasColor = true; + } + } + + if( hasColor ) + { + Quantity_Color aQuanColor( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB ); + AISShape->SetColor( aQuanColor ); + AISShape->SetShadingColor( aQuanColor ); + if ( myShape.ShapeType() == TopAbs_VERTEX ) { + Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect(); + anAspect->SetColor( aQuanColor ); + anAspect->SetScale( myScaleOfMarker ); + anAspect->SetTypeOfMarker( myTypeOfMarker ); + AISShape->Attributes()->SetPointAspect( anAspect ); + } + } + // ... marker type + GEOM::marker_type aType = aGeomObject->GetMarkerType(); + GEOM::marker_size aSize = aGeomObject->GetMarkerSize(); + if ( aType > GEOM::MT_NONE && aType < GEOM::MT_USER && aSize > GEOM::MS_NONE && aSize <= GEOM::MS_70 ) { + Aspect_TypeOfMarker aMType = (Aspect_TypeOfMarker)( (int)aType-1 ); + double aMSize = ((int)aSize+1)*0.5; + Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect(); + anAspect->SetScale( aMSize ); + anAspect->SetTypeOfMarker( aMType ); + Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) ); + if ( hasColor ) + aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB ); + anAspect->SetColor( aQuanColor ); + AISShape->Attributes()->SetPointAspect( anAspect ); + } + else if ( aType == GEOM::MT_USER ) { + int aTextureId = aGeomObject->GetMarkerTexture(); + Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) ); + if ( hasColor ) aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB ); + Standard_Integer aWidth, aHeight; + Handle(Graphic3d_HArray1OfBytes) aTexture = GeometryGUI::getTexture( getStudy(), aTextureId, aWidth, aHeight ); + if ( !aTexture.IsNull() ) { + static int TextureId = 0; + Handle(Prs3d_PointAspect) aTextureAspect = new Prs3d_PointAspect(aQuanColor, + ++TextureId, + aWidth, aHeight, + aTexture ); + AISShape->Attributes()->SetPointAspect( aTextureAspect ); + } + } + } + } + } + } + } + } + // AISShape->SetName(???); ??? necessary to set name ??? occPrs->AddObject( AISShape ); @@ -599,9 +825,9 @@ void GEOM_Displayer::Update( SALOME_VTKPrs* prs ) vtkActorCollection* theActors = 0; - if ( myType == GEOM_MARKER && !myShape.IsNull() && myShape.ShapeType() == TopAbs_FACE ) + if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE ) { - myToActivate = false; + //myToActivate = false; // ouv: commented to make the trihedron pickable (see IPAL18657) GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New(); if ( HasColor() ) @@ -627,7 +853,9 @@ void GEOM_Displayer::Update( SALOME_VTKPrs* prs ) theActors->AddItem( aTrh ); } else - theActors = GEOM_AssemblyBuilder::BuildActors( myShape, 0, 0, Standard_True ); + { + theActors = GEOM_AssemblyBuilder::BuildActors( myShape, 0, 0, Standard_True, myType == GEOM_VECTOR ); + } theActors->InitTraversal(); @@ -750,7 +978,7 @@ SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape ) */ //================================================================= SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry, - SALOME_View* theViewFrame ) + SALOME_View* theViewFrame ) { SALOME_Prs* prs = 0; internalReset(); @@ -763,38 +991,38 @@ SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry, if ( prs ) { Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject(); - theIO->setEntry( entry.latin1() ); + theIO->setEntry( entry.toLatin1().constData() ); if ( !theIO.IsNull() ) { - // set interactive object - setIO( theIO ); - // Find SOBject (because shape should be published previously) - SUIT_Session* session = SUIT_Session::session(); - SUIT_Application* app = session->activeApplication(); - if ( app ) - { - SalomeApp_Study* study = dynamic_cast( app->activeStudy() ); - if ( study ) - { - _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) ); - if ( SO ) - { - // get CORBA reference to data object - CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO); - if ( !CORBA::is_nil( object ) ) - { - // downcast to GEOM object - GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object ); - if ( !GeomObject->_is_nil() ) - { - // finally set shape - setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) ); - myType = GeomObject->GetType(); - } - } - } - } - } + // set interactive object + setIO( theIO ); + // Find SOBject (because shape should be published previously) + SUIT_Session* session = SUIT_Session::session(); + SUIT_Application* app = session->activeApplication(); + if ( app ) + { + SalomeApp_Study* study = dynamic_cast( app->activeStudy() ); + if ( study ) + { + _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) ); + if ( SO ) + { + // get CORBA reference to data object + CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO); + if ( !CORBA::is_nil( object ) ) + { + // downcast to GEOM object + GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object ); + if ( !GeomObject->_is_nil() ) + { + // finally set shape + setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) ); + myType = GeomObject->GetType(); + } + } + } + } + } } UpdatePrs( prs ); // Update presentation by using of the double dispatch } @@ -802,6 +1030,44 @@ SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry, return prs; } +//================================================================= +/*! + * GEOM_Displayer::buildSubshapePresentation + * Builds/finds object's presentation for the current viewer + * Calls corresponding Update() method by means of double dispatch + * For not published objects (for Mantis issue 0020435) + */ +//================================================================= +SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape, + const QString& entry, + SALOME_View* theViewFrame) +{ + SALOME_Prs* prs = 0; + internalReset(); + + myViewFrame = theViewFrame ? theViewFrame : GetActiveView(); + + if (myViewFrame) + { + prs = LightApp_Displayer::buildPresentation(entry, theViewFrame); + if (prs) + { + Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject(); + theIO->setEntry(entry.toLatin1().constData()); + if (!theIO.IsNull()) + { + // set interactive object + setIO(theIO); + // finally set shape + setShape(aShape); + myType = GEOM_SUBSHAPE; + } + UpdatePrs(prs); // Update presentation by using of the double dispatch + } + } + return prs; +} + //================================================================= /*! * GEOM_Displayer::internalReset @@ -835,12 +1101,13 @@ void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& the sm->clearFilters(); SALOME_View* vf = GetActiveView(); - if ( vf ) - { - SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() ); - vf->LocalSelection( prs, theMode ); - delete prs; // delete presentation because displayer is its owner - } + if ( vf ) { + if (!theIO.IsNull() && !vf->isVisible(theIO)) + Display(theIO); + SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() ); + vf->LocalSelection( prs, theMode ); + delete prs; // delete presentation because displayer is its owner + } } //================================================================= @@ -865,7 +1132,7 @@ void GEOM_Displayer::GlobalSelection( const int theMode, const bool update ) */ //================================================================= void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes, - const bool update ) + const bool update, const QList* theSubShapes ) { SUIT_Session* session = SUIT_Session::session(); SalomeApp_Application* app = dynamic_cast( session->activeApplication() ); @@ -899,7 +1166,7 @@ void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes, { ic = viewer->getAISContext(); if ( !ic.IsNull() ) - ic->RemoveFilters(); + ic->RemoveFilters(); } if ( theModes.Contains( GEOM_ALLOBJECTS ) ) @@ -909,19 +1176,29 @@ void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes, if ( theModes.Extent() == 1 ) { int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key(); - aFilter = getFilter( aMode ); + + if ( aMode == GEOM_COMPOUNDFILTER ) + aFilter = getComplexFilter( theSubShapes ); + else + aFilter = getFilter( aMode ); } else if ( theModes.Extent() > 1 ) { TColStd_MapOfInteger aTopAbsModes; TColStd_MapIteratorOfMapOfInteger anIter( theModes ); - QPtrList aListOfFilters; + QList aListOfFilters; for ( ; anIter.More(); anIter.Next() ) - { - SUIT_SelectionFilter* aFilter = getFilter( anIter.Key() ); - if ( aFilter ) - aListOfFilters.append( aFilter ); - } + { + SUIT_SelectionFilter* aFilter; + int aMode = anIter.Key(); + if ( aMode == GEOM_COMPOUNDFILTER ) + aFilter = getComplexFilter( theSubShapes ); + else + aFilter = getFilter( aMode ); + + if ( aFilter ) + aListOfFilters.append( aFilter ); + } aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR ); } @@ -932,10 +1209,10 @@ void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes, { sm->installFilter( aFilter ); if ( !ic.IsNull() ) - { - Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm ); - ic->AddFilter( anOCCFilter ); - } + { + Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm ); + ic->AddFilter( anOCCFilter ); + } } } @@ -988,7 +1265,13 @@ void GEOM_Displayer::AfterDisplay( SALOME_View*, const SALOME_OCCViewType& ) //================================================================= void GEOM_Displayer::SetColor( const int color ) { - myColor = color; + if ( color == -1 ) + UnsetColor(); + else + { + myColor = color; + myShadingColor = Quantity_Color( (Quantity_NameOfColor)color ); + } } int GEOM_Displayer::GetColor() const @@ -1004,6 +1287,10 @@ bool GEOM_Displayer::HasColor() const void GEOM_Displayer::UnsetColor() { myColor = -1; + + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) ); + myShadingColor = SalomeApp_Tools::color( col ); } //================================================================= @@ -1066,3 +1353,117 @@ void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr ) theSelMgr->setSelectedObjects( toSelect, true ); } + +void GEOM_Displayer::SetName( const char* theName ) +{ + myName = theName; +} + +void GEOM_Displayer::UnsetName() +{ + myName = ""; +} + +SalomeApp_Study* GEOM_Displayer::getStudy() const +{ + return dynamic_cast( myApp->activeStudy() ); +} + +void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO ) +{ + myIO = theIO; +} + +void GEOM_Displayer::setShape( const TopoDS_Shape& theShape ) +{ + myShape = theShape; +} + +bool GEOM_Displayer::canBeDisplayed( const QString& /*entry*/, const QString& viewer_type ) const +{ + return viewer_type==SOCC_Viewer::Type() || viewer_type==SVTK_Viewer::Type(); +} + +int GEOM_Displayer::SetDisplayMode( const int theMode ) +{ + int aPrevMode = myDisplayMode; + if ( theMode != -1 ) + myDisplayMode = theMode; + else + { + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 ); + } + return aPrevMode; +} + +int GEOM_Displayer::GetDisplayMode() const +{ + return myDisplayMode; +} + +int GEOM_Displayer::UnsetDisplayMode() +{ + int aPrevMode = myDisplayMode; + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 ); + return aPrevMode; +} + +SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList& theReservedColors ) +{ + int aHue = -1; + int aTolerance = 64; + int anIterations = 0; + int aPeriod = 5; + + while( 1 ) + { + anIterations++; + if( anIterations % aPeriod == 0 ) + { + aTolerance /= 2; + if( aTolerance < 1 ) + break; + } + //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl; + + aHue = (int)( 360.0 * rand() / RAND_MAX ); + //std::cout << "Hue = " << aHue << std::endl; + + //std::cout << "Auto colors : "; + bool ok = true; + QList::const_iterator it = theReservedColors.constBegin(); + QList::const_iterator itEnd = theReservedColors.constEnd(); + for( ; it != itEnd; ++it ) + { + SALOMEDS::Color anAutoColor = *it; + QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) ); + + int h, s, v; + aQColor.getHsv( &h, &s, &v ); + //std::cout << h << " "; + if( abs( h - aHue ) < aTolerance ) + { + ok = false; + //std::cout << "break (diff = " << abs( h - aHue ) << ")"; + break; + } + } + //std::cout << std::endl; + + if( ok ) + break; + } + + //std::cout << "Hue of the returned color = " << aHue << std::endl; + QColor aColor; + aColor.setHsv( aHue, 255, 255 ); + + SALOMEDS::Color aSColor; + aSColor.R = (double)aColor.red() / 255.0; + aSColor.G = (double)aColor.green() / 255.0; + aSColor.B = (double)aColor.blue() / 255.0; + + return aSColor; +}