From 7ee78f2e756897d5ddb6b64305c02d8d1085d37b Mon Sep 17 00:00:00 2001 From: vsr Date: Mon, 23 Nov 2009 14:46:21 +0000 Subject: [PATCH] Move GeomSelectionTools from BLSURF module to SMESH --- configure.ac | 1 + src/Makefile.am | 3 +- src/PluginUtils/GeomSelectionTools.cxx | 302 +++++++++++++++++++++++++ src/PluginUtils/GeomSelectionTools.h | 80 +++++++ src/PluginUtils/Makefile.am | 60 +++++ 5 files changed, 445 insertions(+), 1 deletion(-) create mode 100644 src/PluginUtils/GeomSelectionTools.cxx create mode 100644 src/PluginUtils/GeomSelectionTools.h create mode 100644 src/PluginUtils/Makefile.am diff --git a/configure.ac b/configure.ac index 7f5e389b6..a1b23e273 100644 --- a/configure.ac +++ b/configure.ac @@ -458,6 +458,7 @@ AC_OUTPUT([ \ src/DriverUNV/Makefile \ src/MEFISTO2/Makefile \ src/OBJECT/Makefile \ + src/PluginUtils/Makefile \ src/SMDS/Makefile \ src/SMESH/Makefile \ src/SMESHClient/Makefile \ diff --git a/src/Makefile.am b/src/Makefile.am index 51c76c599..2cb9a99c4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -49,10 +49,11 @@ if SMESH_ENABLE_GUI OBJECT \ SMESHFiltersSelection \ SMESHGUI \ + PluginUtils \ SMESH_SWIG_WITHIHM \ StdMeshersGUI endif DIST_SUBDIRS = SMDS SMESHDS Controls Driver DriverMED DriverDAT DriverUNV DriverSTL SMESH \ SMESH_I SMESHClient SMESH_SWIG MEFISTO2 StdMeshers StdMeshers_I OBJECT \ - SMESHFiltersSelection SMESHGUI SMESH_SWIG_WITHIHM StdMeshersGUI + SMESHFiltersSelection SMESHGUI PluginUtils SMESH_SWIG_WITHIHM StdMeshersGUI diff --git a/src/PluginUtils/GeomSelectionTools.cxx b/src/PluginUtils/GeomSelectionTools.cxx new file mode 100644 index 000000000..74a5f64c2 --- /dev/null +++ b/src/PluginUtils/GeomSelectionTools.cxx @@ -0,0 +1,302 @@ +// Copyright (C) 2007-2008 CEA/DEN, EDF R&D +// +// 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. +// +// 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 : GeomSelectionTools.cxx +// Authors : Nicolas GEIMER (OCC) +// --- +// + + +#include "GeomSelectionTools.h" + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "utilities.h" + +#include "SALOME_LifeCycleCORBA.hxx" +#include + +/*! + * Constructor + * @param aStudy pointer to the Study + * + */ +GeomSelectionTools::GeomSelectionTools(_PTR(Study) aStudy) +{ + myStudy = aStudy; +} + +/*! + * Accessor to the Study used by this GeomSelectionTools object + * @return The study used by the GeomSelectionTools class + */ +_PTR(Study) GeomSelectionTools::getMyStudy() +{ + return myStudy; +} + +/*! + * Allows to get the Salome Application + * @return A LightApp_SelectionMgr Pointer or 0 if it can't get it. + */ +SalomeApp_Application* GeomSelectionTools::GetSalomeApplication() +{ + SalomeApp_Application* anApp = dynamic_cast( SUIT_Session::session()->activeApplication() ); + if (anApp) + return anApp; + else + return 0; +} + +/*! + * Allows to get the selection manager from LightApp + * @return A LightApp_SelectionMgr Pointer or 0 if it can't get it. + */ +LightApp_SelectionMgr* GeomSelectionTools::selectionMgr() +{ + SalomeApp_Application* anApp = GetSalomeApplication(); + if (anApp) + return dynamic_cast( anApp->selectionMgr() ); + else + return 0; +} + +/*! + * Return the list of the selected Salome Interactive Object (SALOME_ListIO*) + * @return the list of the selected Salome Interactive Object + */ +SALOME_ListIO* GeomSelectionTools::getSelectedSalomeObjects() +{ + SALOME_ListIO* selected; + LightApp_SelectionMgr* aSel = selectionMgr(); + aSel->selectedObjects( *selected, NULL, false ); + return selected; +} + +/*! + * Return the first selected Salome Interactive Object (Handle(Salome_InteractiveObject)) + * @return the first selected Salome Interactive Object + */ +Handle(SALOME_InteractiveObject) GeomSelectionTools::getFirstSelectedSalomeObject() +{ + SALOME_ListIO selected; + LightApp_SelectionMgr* aSel = selectionMgr(); + aSel->selectedObjects( selected, NULL, false ); + if (!selected.IsEmpty()){ + SALOME_ListIteratorOfListIO anIt(selected); + Handle(SALOME_InteractiveObject) anIO; + anIO = anIt.Value(); + return anIO; + } + return NULL; +} + +/*! + * Return the entry of the first selected Object + * @return the entry of the first selected Object + */ +std::string GeomSelectionTools::getFirstSelectedEntry() +{ + Handle(SALOME_InteractiveObject) anIO; + std::string entry=""; + anIO=GeomSelectionTools::getFirstSelectedSalomeObject(); + return GeomSelectionTools::getEntryOfObject(anIO); +} + +/*! + * Return the entry of a Salome Interactive Object + * @param anIO the Handle of the Salome Interactive Object + * @return the entry of the Salome Interactive Object + */ +std::string GeomSelectionTools::getEntryOfObject(Handle(SALOME_InteractiveObject) anIO){ + std::string entry=""; + _PTR(SObject) aSO = myStudy->FindObjectID(anIO->getEntry()); + if (aSO){ + _PTR(SObject) aRefSObj; + // If selected object is a reference + if ( aSO->ReferencedObject( aRefSObj )) + entry = aRefSObj->GetID(); + // If selected object is a reference is not a reference + else + entry= anIO->getEntry(); + } + return entry; +} + +/*! + * Retrieve the name from the entry of the object + * @param entry the entry of the object + * @return the name of the object + */ +std::string GeomSelectionTools::getNameFromEntry(std::string entry){ + std::string name = ""; + _PTR(SObject) aSO = myStudy->FindObjectID(entry); + if (aSO){ + _PTR(SObject) aRefSObj; + // If selected object is a reference + if ( aSO->ReferencedObject( aRefSObj )) + name = aRefSObj->GetName(); + // If selected object is a reference is not a reference + else + name = aSO->GetName(); + } + return name; +} + + +/*! + * Retrieve the component type of the first selected object, it manages successfully references. + * @return the component type of the first selected object + */ +std::string GeomSelectionTools::getFirstSelectedComponentDataType() +{ + Handle(SALOME_InteractiveObject) anIO; + std::string DataType=""; + anIO=GeomSelectionTools::getFirstSelectedSalomeObject(); + _PTR(SObject) aSO = myStudy->FindObjectID(anIO->getEntry()); + if (aSO){ + _PTR(SObject) aRefSObj; + // If selected object is a reference + if ( aSO->ReferencedObject( aRefSObj )) + DataType= aRefSObj->GetFatherComponent()->ComponentDataType(); + // If selected object is a reference is not a reference + else + DataType=anIO->getComponentDataType(); + } + return DataType; +} + +/*! + * Retrieve the shape type from the entry + * @return the shape type from the entry, return TopAbs_SHAPE if the object does not define a shape or a group. + */ +TopAbs_ShapeEnum GeomSelectionTools::entryToShapeType(std::string entry){ +// MESSAGE("GeomSelectionTools::entryToShapeType"<FindObjectID(entry); + if (aSO){ + _PTR(SObject) aRefSObj; + GEOM::GEOM_Object_var aShape; + // MESSAGE("Got a SO"); + // If selected object is a reference + if ( aSO->ReferencedObject( aRefSObj )) + aSO = aRefSObj; + // MESSAGE("aSO->GetFatherComponent()->ComponentDataType(): " << aSO->GetFatherComponent()->ComponentDataType()); + if ( strcmp(aSO->GetFatherComponent()->ComponentDataType().c_str(),"GEOM") == 0) + aShape = SMESH::SObjectToInterface(aSO); + if ( !aShape->_is_nil() ){ + // MESSAGE("Got the Geom Object "); + // MESSAGE("Geom Object Type "<< aShape->GetType()); + SalomeApp_Application* anApp = GetSalomeApplication(); + if (anApp) { +// MESSAGE("Got Application"); + Engines::Component_var component = anApp->lcc()->FindOrLoad_Component( "FactoryServer","GEOM" ); + GEOM::GEOM_Gen_var _geomEngine = GEOM::GEOM_Gen::_narrow(component); +// MESSAGE("Got GEOM engine"); + // if the Geom Object is a group + if (aShape->GetType() == GEOM_GROUP){ +// MESSAGE("It's a group"); + GEOM::GEOM_IGroupOperations_var aGroupOp = _geomEngine->GetIGroupOperations(myStudy->StudyId()); + ShapeType= (TopAbs_ShapeEnum)aGroupOp->GetType(aShape); + } + // if not + else { + GEOM_Client* aClient = new GEOM_Client(); + if ( aClient && !_geomEngine->_is_nil() ) { +// MESSAGE("GEOM client is OK and GEOM engine is not null"); + S = aClient->GetShape( _geomEngine, aShape ); + ShapeType=S.ShapeType(); + } + } + } + } + } +// MESSAGE("ShapeType returned is " << ShapeType); + return ShapeType; +} + +/*! + * Gives the ShapeType of the first Selected Object, return TopAbs_SHAPE if the first selected object does not define a shape. + * @return the ShapeType of the first Selected Object, return TopAbs_SHAPE if the first selected object does not define a shape. + */ +TopAbs_ShapeEnum GeomSelectionTools:: getFirstSelectedShapeType() +{ + Handle(SALOME_InteractiveObject) anIO; + anIO=GeomSelectionTools::getFirstSelectedSalomeObject(); + return entryToShapeType(anIO->getEntry()); +} + +/*! + * Print information to std output of the face + * and return the OCC type of face: Plane, Cylinder,Cone, Sphere, Torus, BezierSurface,BSplineSurface, SurfaceOfRevolution,SurfaceOfExtrusion, OtherSurface + * @param TopoDS_Shape S Face we want information about. + * @return the OCC type of face: Plane, Cylinder,Cone, Sphere, Torus, BezierSurface,BSplineSurface, SurfaceOfRevolution,SurfaceOfExtrusion, OtherSurface + * return Other_Surface if the selected face is not a face. + * Information printed is : + * U and V degrees + * U and V number of poles + * U and V number of knots + * U or V is Rational ? + * + */ +GeomAbs_SurfaceType GeomSelectionTools::getFaceInformation(TopoDS_Shape S) +{ + GeomAbs_SurfaceType surf_type=GeomAbs_OtherSurface ; + if (!S.IsNull() && S.ShapeType()==TopAbs_FACE){ + TopoDS_Face f=TopoDS::Face(S); + Handle(Geom_Surface) surf = BRep_Tool::Surface(f); + BRepAdaptor_Surface surf_adap=BRepAdaptor_Surface::BRepAdaptor_Surface(f); + + /* Global Information */ + std::cout << "GLOBAL INFORMATION" << std::endl; + std::cout << "******************" << std::endl; + std::stringstream buffer; + buffer << "Degre U : " << surf_adap.UDegree(); + //conversion nécessaire pour affichage + std::cout << buffer.str() << std::endl; + std::cout << " Degre V : " << surf_adap.VDegree() << std::endl; + std::cout << " Nb Poles U : " << surf_adap.NbUPoles() << std::endl; + std::cout << " Nb Poles V : " << surf_adap.NbVPoles() << std::endl; + std::cout << " Nb Noeuds U : " << surf_adap.NbUKnots() << std::endl; + std::cout << " Nb Noeuds V : " << surf_adap.NbVKnots() << std::endl; + std::cout << " U Rationnel ? " << surf_adap.IsURational() << std::endl; + std::cout << " V Rationnel ? " << surf_adap.IsVRational() << std::endl; + + surf_type=surf_adap.GetType(); + } + return surf_type; +} + + + + diff --git a/src/PluginUtils/GeomSelectionTools.h b/src/PluginUtils/GeomSelectionTools.h new file mode 100644 index 000000000..2ec4e9f9d --- /dev/null +++ b/src/PluginUtils/GeomSelectionTools.h @@ -0,0 +1,80 @@ +// Copyright (C) 2007-2008 CEA/DEN, EDF R&D +// +// 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. +// +// 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 : GeomSelectionTools.h +// Authors : Nicolas GEIMER (OCC) +// --- +#ifndef _GEOMSELECTIONTOOLS_H_ +#define _GEOMSELECTIONTOOLS_H_ + +#ifdef WIN32 +# ifdef GeomSelectionTools_EXPORTS +# define GEOMSELECTIONTOOLS_EXPORT __declspec( dllexport ) +# else +# define GEOMSELECTIONTOOLS_EXPORT __declspec( dllimport ) +# endif +#else +# define GEOMSELECTIONTOOLS_EXPORT +#endif + +#include "SALOMEDSClient.hxx" +#include "SALOME_InteractiveObject.hxx" +#include +#include + +#include +#include + +class LightApp_SelectionMgr; + + +/*! + * The GeomSelectionTools class gives high level tools to select Geom (and other objects) + * A specific attention has been given to analyze selected GEOM objects. + * + * @param myStudy This class is specific to the study ! + * + */ + +class GEOMSELECTIONTOOLS_EXPORT GeomSelectionTools +{ + +private: + + _PTR(Study) myStudy; + +public: + + GeomSelectionTools(_PTR(Study)); + static SalomeApp_Application* GetSalomeApplication(); + static LightApp_SelectionMgr* selectionMgr(); + SALOME_ListIO* getSelectedSalomeObjects(); + Handle(SALOME_InteractiveObject) getFirstSelectedSalomeObject(); + std::string getFirstSelectedEntry(); + std::string getEntryOfObject(Handle(SALOME_InteractiveObject)); + std::string getNameFromEntry(std::string); + std::string getFirstSelectedComponentDataType(); + TopAbs_ShapeEnum getFirstSelectedShapeType(); + TopAbs_ShapeEnum entryToShapeType(std::string ); + GeomAbs_SurfaceType getFaceInformation(TopoDS_Shape); + _PTR(Study) getMyStudy(); +}; + + +#endif // _GEOMSELECTIONTOOLS_H_ + diff --git a/src/PluginUtils/Makefile.am b/src/PluginUtils/Makefile.am new file mode 100644 index 000000000..6cd30164a --- /dev/null +++ b/src/PluginUtils/Makefile.am @@ -0,0 +1,60 @@ +# Copyright (C) 2007-2008 CEA/DEN, EDF R&D +# +# 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. +# +# 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 : Makefile.am +# Author : Nicolas GEIMER (OCC) +# --- +# +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +# header files +salomeinclude_HEADERS = \ + GeomSelectionTools.h + +# Libraries targets +lib_LTLIBRARIES = libGeomSelectionTools.la + +dist_libGeomSelectionTools_la_SOURCES = \ + GeomSelectionTools.h \ + GeomSelectionTools.cxx + +# additionnal information to compil and link file +libGeomSelectionTools_la_CPPFLAGS = \ + $(QT_INCLUDES) \ + $(CAS_CPPFLAGS) \ + $(PYTHON_INCLUDES) \ + $(KERNEL_CXXFLAGS) \ + $(GUI_CXXFLAGS) \ + $(GEOM_CXXFLAGS) \ + $(MED_CXXFLAGS) \ + $(BOOST_CPPFLAGS) \ + $(CORBA_CXXFLAGS) \ + $(CORBA_INCLUDES) \ + -I$(srcdir)/../SMESHGUI \ + -I$(top_builddir)/idl + +libGeomSelectionTools_la_LDFLAGS = \ + ../../idl/libSalomeIDLSMESH.la \ + ../SMESHGUI/libSMESH.la \ + $(QT_LIBS) \ + $(CORBA_LIBS) \ + $(KERNEL_LDFLAGS) -lSalomeIDLKernel -lSALOMELocalTrace -lSalomeLifeCycleCORBA \ + $(GUI_LDFLAGS) -lSalomeObject -lsuit -lLightApp -lSalomeApp \ + $(GEOM_LDFLAGS) -lSalomeIDLGEOM -lGEOMClient \ + $(CAS_KERNEL) -lTKBRep -lTKG3d -- 2.39.2