-// GEOM GEOMGUI : GUI for Geometry component
+// GEOM GEOMGUI : GUI for Geometry component
//
-// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// Copyright (C) 2003 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
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
+// File : GEOM_Displayer.cxx
+// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
//
-//
-// File : GEOM_Displayer.cxx
-// Author : Vadim SANDLER
-// Module : GEOM
-// $Header$
#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_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_AISVector.hxx"
-#include "GEOM_AISTrihedron.hxx"
-#include "GEOM_VTKTrihedron.hxx"
+#include <GEOM_Actor.h>
+#include <GEOM_AssemblyBuilder.h>
+#include <GEOM_AISShape.hxx>
+#include <GEOM_AISVector.hxx>
+#include <GEOM_AISTrihedron.hxx>
+#include <GEOM_VTKTrihedron.hxx>
#include <SUIT_Desktop.h>
#include <SUIT_ViewWindow.h>
#include <SUIT_Session.h>
-#include <SUIT_Tools.h>
#include <SUIT_ViewManager.h>
+#include <SUIT_ResourceMgr.h>
#include <SalomeApp_Study.h>
#include <SalomeApp_Application.h>
#include <SalomeApp_Tools.h>
#include <SALOME_ListIteratorOfListIO.hxx>
+#include <SALOME_ListIO.hxx>
+#include <SALOME_Prs.h>
#include <SOCC_Prs.h>
#include <SOCC_ViewModel.h>
#include <SVTK_Prs.h>
#include <SVTK_ViewModel.h>
-#include <SALOMEDSClient.hxx>
-#include <SALOMEDSClient_SObject.hxx>
-
// OCCT Includes
#include <AIS_Drawer.hxx>
#include <AIS_ListIteratorOfListOfInteractive.hxx>
#include <Prs3d_IsoAspect.hxx>
#include <Prs3d_PointAspect.hxx>
-#include <Graphic3d_AspectMarker3d.hxx>
#include <StdSelect_TypeOfEdge.hxx>
#include <StdSelect_TypeOfFace.hxx>
#include <TopoDS_Face.hxx>
#include <gp_Pln.hxx>
#include <TColStd_MapOfInteger.hxx>
#include <TColStd_MapIteratorOfMapOfInteger.hxx>
+#include <TopoDS_Iterator.hxx>
// VTK Includes
#include <vtkActorCollection.h>
#include <vtkProperty.h>
-// STL Includes
-#include <cstring>
-
// CORBA Headers
#include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
-#include "GEOMImpl_Types.hxx"
+#include <GEOMImpl_Types.hxx>
using namespace std;
if ( app )
{
SUIT_Desktop* desk = app->desktop();
- QPtrList<SUIT_ViewWindow> wnds = desk->windows();
+ QList<SUIT_ViewWindow*> wnds = desk->windows();
SUIT_ViewWindow* wnd;
- for ( wnd = wnds.first(); wnd; wnd = wnds.next() )
+ QListIterator<SUIT_ViewWindow*> it( wnds );
+ while ( it.hasNext() && (wnd = it.next()) )
{
SUIT_ViewManager* vman = wnd->getViewManager();
if ( vman )
Handle(GEOM_AISShape) AISShape;
if (myType == GEOM_VECTOR)
AISShape = new GEOM_AISVector (myShape, "");
- else
+ 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->setIO( anObj );
AISShape->SetOwner( anObj );
}
+
+ // Get color from GEOM_Object
+ SUIT_Session* session = SUIT_Session::session();
+ SUIT_Application* app = session->activeApplication();
+ if ( app )
+ {
+ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( 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<SALOMEDS::Color> aReservedColors;
+
+ SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( 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( 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 );
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
// AISShape->SetName(???); ??? necessary to set name ???
occPrs->AddObject( AISShape );
if ( prs )
{
Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
- theIO->setEntry( entry.latin1() );
+ theIO->setEntry( entry.toLatin1().constData() );
if ( !theIO.IsNull() )
{
// set interactive object
{
TColStd_MapOfInteger aTopAbsModes;
TColStd_MapIteratorOfMapOfInteger anIter( theModes );
- QPtrList<SUIT_SelectionFilter> aListOfFilters;
+ QList<SUIT_SelectionFilter*> aListOfFilters;
for ( ; anIter.More(); anIter.Next() )
{
SUIT_SelectionFilter* aFilter = getFilter( anIter.Key() );
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<SALOMEDS::Color>& 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;
+ }
+ //cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< endl;
+
+ aHue = (int)( 360.0 * rand() / RAND_MAX );
+ //cout << "Hue = " << aHue << endl;
+
+ //cout << "Auto colors : ";
+ bool ok = true;
+ QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
+ QList<SALOMEDS::Color>::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 );
+ //cout << h << " ";
+ if( abs( h - aHue ) < aTolerance )
+ {
+ ok = false;
+ //cout << "break (diff = " << abs( h - aHue ) << ")";
+ break;
+ }
+ }
+ //cout << endl;
+
+ if( ok )
+ break;
+ }
+
+ //cout << "Hue of the returned color = " << aHue << 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;
}