1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : GeomSelectionTools.cxx
21 // Authors : Nicolas GEIMER (OCC)
26 #include "GeomSelectionTools.h"
29 #include <LightApp_SelectionMgr.h>
30 #include <SalomeApp_Application.h>
31 #include <SUIT_Session.h>
33 #include <SALOME_ListIteratorOfListIO.hxx>
34 #include <GEOM_Client.hxx>
35 #include <SMESH_Gen_i.hxx>
36 #include <SMESHGUI_Utils.h>
37 #include <boost/shared_ptr.hpp>
40 #include <BRep_Tool.hxx>
41 #include <Handle_Geom_Surface.hxx>
42 #include <BRepAdaptor_Surface.hxx>
47 * @param aStudy pointer to the Study
50 GeomSelectionTools::GeomSelectionTools(_PTR(Study) aStudy)
56 * Accessor to the Study used by this GeomSelectionTools object
57 * @return The study used by the GeomSelectionTools class
59 _PTR(Study) GeomSelectionTools::getMyStudy()
65 * Allows to get the selection manager from LightApp
66 * @return A LightApp_SelectionMgr Pointer or 0 if it can't get it.
68 LightApp_SelectionMgr* GeomSelectionTools::selectionMgr()
70 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
72 return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
78 * Return the list of the selected Salome Interactive Object (SALOME_ListIO*)
79 * @return the list of the selected Salome Interactive Object
81 SALOME_ListIO* GeomSelectionTools::getSelectedSalomeObjects()
83 SALOME_ListIO* selected;
84 LightApp_SelectionMgr* aSel = selectionMgr();
85 aSel->selectedObjects( *selected, NULL, false );
90 * Return the first selected Salome Interactive Object (Handle(Salome_InteractiveObject))
91 * @return the first selected Salome Interactive Object
93 Handle(SALOME_InteractiveObject) GeomSelectionTools::getFirstSelectedSalomeObject()
95 SALOME_ListIO selected;
96 LightApp_SelectionMgr* aSel = selectionMgr();
97 aSel->selectedObjects( selected, NULL, false );
98 if (!selected.IsEmpty()){
99 SALOME_ListIteratorOfListIO anIt(selected);
100 Handle(SALOME_InteractiveObject) anIO;
108 * Return the entry of the first selected Object
109 * @return the entry of the first selected Object
111 std::string GeomSelectionTools::getFirstSelectedEntry()
113 Handle(SALOME_InteractiveObject) anIO;
114 std::string entry="";
115 anIO=GeomSelectionTools::getFirstSelectedSalomeObject();
116 return GeomSelectionTools::getEntryOfObject(anIO);
120 * Return the entry of a Salome Interactive Object
121 * @param anIO the Handle of the Salome Interactive Object
122 * @return the entry of the Salome Interactive Object
124 std::string GeomSelectionTools::getEntryOfObject(Handle(SALOME_InteractiveObject) anIO){
125 std::string entry="";
126 _PTR(SObject) aSO = myStudy->FindObjectID(anIO->getEntry());
128 _PTR(SObject) aRefSObj;
129 // If selected object is a reference
130 if ( aSO->ReferencedObject( aRefSObj ))
131 entry = aRefSObj->GetID();
132 // If selected object is a reference is not a reference
134 entry= anIO->getEntry();
140 * Retrieve the name from the entry of the object
141 * @param entry the entry of the object
142 * @return the name of the object
144 std::string GeomSelectionTools::getNameFromEntry(std::string entry){
145 std::string name = "";
146 _PTR(SObject) aSO = myStudy->FindObjectID(entry);
148 _PTR(SObject) aRefSObj;
149 // If selected object is a reference
150 if ( aSO->ReferencedObject( aRefSObj ))
151 name = aRefSObj->GetName();
152 // If selected object is a reference is not a reference
154 name = aSO->GetName();
161 * Retrieve the component type of the first selected object, it manages successfully references.
162 * @return the component type of the first selected object
164 std::string GeomSelectionTools::getFirstSelectedComponentDataType()
166 Handle(SALOME_InteractiveObject) anIO;
167 std::string DataType="";
168 anIO=GeomSelectionTools::getFirstSelectedSalomeObject();
169 _PTR(SObject) aSO = myStudy->FindObjectID(anIO->getEntry());
171 _PTR(SObject) aRefSObj;
172 // If selected object is a reference
173 if ( aSO->ReferencedObject( aRefSObj ))
174 DataType= aRefSObj->GetFatherComponent()->ComponentDataType();
175 // If selected object is a reference is not a reference
177 DataType=anIO->getComponentDataType();
183 * Retrieve the TopoDS shape from the first selected object
184 * @return the TopoDS shape from the first selected object, empty TopoDS Shape if a shape is not selected.
186 TopoDS_Shape GeomSelectionTools::getFirstSelectedTopoDSShape()
188 Handle(SALOME_InteractiveObject) anIO;
189 anIO=GeomSelectionTools::getFirstSelectedSalomeObject();
190 return entryToShape(anIO->getEntry());
194 * Retrieve the TopoDS shape from the entry
195 * @return the TopoDS shape from the entry, empty TopoDS Shape if the entry does not define a shape.
197 TopoDS_Shape GeomSelectionTools::entryToShape(std::string entry){
198 TopoDS_Shape S = TopoDS_Shape();
199 _PTR(SObject) aSO = myStudy->FindObjectID(entry);
201 _PTR(SObject) aRefSObj;
202 GEOM::GEOM_Object_var aShape;
203 // If selected object is a reference
204 if ( aSO->ReferencedObject( aRefSObj )){
205 if (aRefSObj->GetFatherComponent()->ComponentDataType() == "GEOM")
206 aShape=SMESH::SObjectToInterface<GEOM::GEOM_Object>(aRefSObj);
208 // If selected object is a reference is not a reference
210 if ( aSO->GetFatherComponent()->ComponentDataType() == "GEOM")
211 aShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>(aSO);
213 if ( !aShape->_is_nil() ){
214 if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen())
215 S=gen->GeomObjectToShape( aShape.in() );
222 * Gives the ShapeType of the first Selected Object, return TopAbs_SHAPE if the first selected object does not define a shape.
223 * @return the ShapeType of the first Selected Object, return TopAbs_SHAPE if the first selected object does not define a shape.
225 TopAbs_ShapeEnum GeomSelectionTools:: getFirstSelectedShapeType()
227 TopoDS_Shape S=getFirstSelectedTopoDSShape();
229 return S.ShapeType();
235 * Print information to std output of the face (if the first selected object is a face)
236 * and return the OCC type of face: Plane, Cylinder,Cone, Sphere, Torus, BezierSurface,BSplineSurface, SurfaceOfRevolution,SurfaceOfExtrusion, OtherSurface
237 * @return the OCC type of face: Plane, Cylinder,Cone, Sphere, Torus, BezierSurface,BSplineSurface, SurfaceOfRevolution,SurfaceOfExtrusion, OtherSurface
238 * return Other_Surface if the selected face is not a face.
239 * Information printed is :
241 * U and V number of poles
242 * U and V number of knots
243 * U or V is Rational ?
246 GeomAbs_SurfaceType GeomSelectionTools::getFaceInformation()
248 TopoDS_Shape S=getFirstSelectedTopoDSShape();
249 GeomAbs_SurfaceType surf_type=GeomAbs_OtherSurface ;
250 if (!S.IsNull() && S.ShapeType()==TopAbs_FACE){
251 TopoDS_Face f=TopoDS::Face(S);
252 Handle(Geom_Surface) surf = BRep_Tool::Surface(f);
253 BRepAdaptor_Surface surf_adap=BRepAdaptor_Surface::BRepAdaptor_Surface(f);
255 /* Global Information */
256 cout << "GLOBAL INFORMATION" << endl;
257 cout << "******************" << endl;
259 buffer << "Degre U : " << surf_adap.UDegree();
260 //conversion nécessaire pour affichage
261 cout << buffer.str() << endl;
262 cout << " Degre V : " << surf_adap.VDegree() << endl;
263 cout << " Nb Poles U : " << surf_adap.NbUPoles() << endl;
264 cout << " Nb Poles V : " << surf_adap.NbVPoles() << endl;
265 cout << " Nb Noeuds U : " << surf_adap.NbUKnots() << endl;
266 cout << " Nb Noeuds V : " << surf_adap.NbVKnots() << endl;
267 cout << " U Rationnel ? " << surf_adap.IsURational() << endl;
268 cout << " V Rationnel ? " << surf_adap.IsVRational() << endl;
270 surf_type=surf_adap.GetType();