-// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
//
-// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// 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
-// 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
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// GEOM GEOMGUI : GUI for Geometry component
#include <OCCViewer_ViewPort3d.h>
#include <OCCViewer_ViewModel.h>
#include <OCCViewer_ViewWindow.h>
+#include <SOCC_ViewModel.h>
+#include <SOCC_Prs.h>
#include <SALOME_ListIO.hxx>
#include <SALOME_ListIteratorOfListIO.hxx>
//=====================================================================================
// function : GetIndex()
-// purpose : Get the index of a sub shape in a main shape : index start at 1
+// purpose : Get the index of a sub-shape in a main shape : index start at 1
//=====================================================================================
int GEOMBase::GetIndex( const TopoDS_Shape& subshape, const TopoDS_Shape& shape )
{
foreach ( SUIT_ViewWindow* view, views ) {
if ( view && view->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
- Handle(AIS_InteractiveContext) anIC = ((OCCViewer_Viewer*)view->getViewManager()->getViewModel())->getAISContext();
-
- AIS_ListOfInteractive displayed;
- anIC->DisplayedObjects( displayed );
- anIC->ObjectsInCollector( displayed );
-
- AIS_ListIteratorOfListOfInteractive it( displayed );
- for ( ; it.More(); it.Next() ){
- if ( onlyGeom && !it.Value()->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) )
- continue;
-
- Handle(SALOME_InteractiveObject) obj =
- Handle(SALOME_InteractiveObject)::DownCast( it.Value()->GetOwner() );
-
- if ( !obj.IsNull() && obj->isSame( IO ) )
- {
- aisObject = it.Value();
- break;
- }
+ OCCViewer_Viewer* occViewer=(OCCViewer_Viewer*)view->getViewManager()->getViewModel();
+ SOCC_Viewer* soccViewer = dynamic_cast<SOCC_Viewer*>(occViewer);
+ if (soccViewer) {
+ SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( soccViewer->CreatePrs( IO->getEntry() ) );
+ if ( occPrs && !occPrs->IsNull() ) {
+ AIS_ListOfInteractive shapes; occPrs->GetObjects( shapes );
+ if( !shapes.Extent() ) continue;
+ aisObject=shapes.First();
+ delete occPrs;
+ }
}
}
if ( !aisObject.IsNull() ) break;
- }
+ } // foreach
}
return aisObject;
{
QString name;
SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
- CORBA::String_var IOR = SalomeApp_Application::orb()->object_to_string( object );
- if ( study && strcmp( IOR.in(), "" ) != 0 ) {
- _PTR(SObject) aSObj( study->studyDS()->FindObjectIOR( std::string( IOR.in() ) ) );
- _PTR(GenericAttribute) anAttr;
- if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") ) {
- _PTR(AttributeName) aNameAttr( anAttr );
- name = aNameAttr->Value().c_str();
+
+ if ( !CORBA::is_nil( object ) ) {
+ // 1. search if object is already published in the study
+ CORBA::String_var IOR = SalomeApp_Application::orb()->object_to_string( object );
+ if ( study && strcmp( IOR.in(), "" ) != 0 ) {
+ _PTR(SObject) aSObj( study->studyDS()->FindObjectIOR( std::string( IOR.in() ) ) );
+ _PTR(GenericAttribute) anAttr;
+ if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") ) {
+ _PTR(AttributeName) aNameAttr( anAttr );
+ name = aNameAttr->Value().c_str();
+ }
+ }
+
+ // 2. if object is not found in the study, try default name
+ if ( name.isEmpty() ) {
+ if ( object->IsMainShape() ) {
+ name = GetDefaultName( "geomObj" );
+ }
+ else {
+ GEOM::GEOM_Object_var mainShape = object->GetMainShape();
+ if ( !CORBA::is_nil( mainShape ) ) {
+ GEOM::ListOfLong_var indices = object->GetSubShapeIndices();
+ if ( indices->length() > 0 ) {
+ TopAbs_ShapeEnum type = (TopAbs_ShapeEnum)( object->GetShapeType() );
+ name = QString( "%1:%2_%3" ).arg( GetName( mainShape.in() ) )
+ .arg( TypeName( type ) ).arg( indices[0] );
+ }
+ }
+ }
}
}
{
return !object->_is_nil() && object->IsShape();
}
+
+//=======================================================================
+// function : TypeName()
+// purpose : Get string representation for the shape type
+//=======================================================================
+QString GEOMBase::TypeName( TopAbs_ShapeEnum type )
+{
+ QString name = "shape";
+ switch( type ) {
+ case TopAbs_COMPSOLID:
+ name = "compsolid"; break;
+ case TopAbs_COMPOUND:
+ name = "compound"; break;
+ case TopAbs_SOLID:
+ name = "solid"; break;
+ case TopAbs_SHELL:
+ name = "shell"; break;
+ case TopAbs_FACE:
+ name = "face"; break;
+ case TopAbs_WIRE:
+ name = "wire"; break;
+ case TopAbs_EDGE:
+ name = "edge"; break;
+ case TopAbs_VERTEX:
+ name = "vertex"; break;
+ default:
+ break;
+ }
+ return name;
+}
+
+//================================================================
+// Function : GetEntry
+// Purpose : Get study entry for the given object (if it is published)
+//================================================================
+QString GEOMBase::GetEntry( GEOM::GEOM_Object_ptr object )
+{
+ QString entry;
+ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
+ if ( study && !CORBA::is_nil( object ) ) {
+ QString objIOR = GetIORFromObject( object );
+ if ( !objIOR.isEmpty() ) {
+ _PTR(SObject) SO( study->studyDS()->FindObjectIOR( objIOR.toLatin1().constData() ) );
+ if ( SO )
+ entry = SO->GetID().c_str();
+ }
+ }
+ return entry;
+}
+
+//================================================================
+// Function : PublishSubObject
+// Purpose : Publish sub-shape under the main object
+//================================================================
+void GEOMBase::PublishSubObject( GEOM::GEOM_Object_ptr object )
+{
+ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
+ if ( study && !CORBA::is_nil( object ) ) {
+ _PTR(Study) studyDS = study->studyDS();
+ QString entry = GetEntry( object );
+ GEOM::GEOM_Object_var father = object->GetMainShape();
+ QString fatherEntry = GetEntry( father );
+ if ( entry.isEmpty() && !CORBA::is_nil( father ) && !fatherEntry.isEmpty() ) {
+ QString name = GetName( object );
+ GeometryGUI::GetGeomGen()->AddInStudy( GeometryGUI::ClientStudyToStudy( studyDS ),
+ object, name.toLatin1().data(), father.in() );
+ }
+ }
+}