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>
43 #include <GeomAbs_SurfaceType.hxx>
45 GeomSelectionTools::GeomSelectionTools(_PTR(Study) aStudy)
52 LightApp_SelectionMgr* GeomSelectionTools::selectionMgr()
54 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
56 return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
61 SALOME_ListIO* GeomSelectionTools::getSelectedSalomeObjects()
63 SALOME_ListIO* selected;
64 LightApp_SelectionMgr* aSel = selectionMgr();
65 aSel->selectedObjects( *selected, NULL, false );
70 Handle(SALOME_InteractiveObject) GeomSelectionTools::getFirstSelectedSalomeObject()
72 SALOME_ListIO selected;
73 LightApp_SelectionMgr* aSel = selectionMgr();
74 aSel->selectedObjects( selected, NULL, false );
75 if (!selected.IsEmpty()){
76 SALOME_ListIteratorOfListIO anIt(selected);
77 Handle(SALOME_InteractiveObject) anIO;
84 std::string GeomSelectionTools::getFirstSelectedEntry()
86 Handle(SALOME_InteractiveObject) anIO;
88 anIO=GeomSelectionTools::getFirstSelectedSalomeObject();
89 return GeomSelectionTools::getEntryOfObject(anIO);
92 std::string GeomSelectionTools::getEntryOfObject(Handle(SALOME_InteractiveObject) anIO){
94 _PTR(SObject) aSO = myStudy->FindObjectID(anIO->getEntry());
96 _PTR(SObject) aRefSObj;
97 // If selected object is a reference
98 if ( aSO->ReferencedObject( aRefSObj ))
99 entry = aRefSObj->GetID();
100 // If selected object is a reference is not a reference
102 entry= anIO->getEntry();
108 std::string GeomSelectionTools::getNameFromEntry(std::string entry){
109 std::string name = "";
110 _PTR(SObject) aSO = myStudy->FindObjectID(entry);
112 _PTR(SObject) aRefSObj;
113 // If selected object is a reference
114 if ( aSO->ReferencedObject( aRefSObj ))
115 name = aRefSObj->GetName();
116 // If selected object is a reference is not a reference
118 name = aSO->GetName();
123 std::string GeomSelectionTools::getFirstSelectedComponentDataType()
125 Handle(SALOME_InteractiveObject) anIO;
126 std::string DataType="";
127 anIO=GeomSelectionTools::getFirstSelectedSalomeObject();
128 _PTR(SObject) aSO = myStudy->FindObjectID(anIO->getEntry());
130 _PTR(SObject) aRefSObj;
131 // If selected object is a reference
132 if ( aSO->ReferencedObject( aRefSObj ))
133 DataType= aRefSObj->GetFatherComponent()->ComponentDataType();
134 // If selected object is a reference is not a reference
136 DataType=anIO->getComponentDataType();
141 TopoDS_Shape GeomSelectionTools::getFirstSelectedTopoDSShape()
143 Handle(SALOME_InteractiveObject) anIO;
144 anIO=GeomSelectionTools::getFirstSelectedSalomeObject();
145 return entryToShape(anIO->getEntry());
148 TopoDS_Shape GeomSelectionTools::entryToShape(std::string entry){
149 TopoDS_Shape S = TopoDS_Shape();
150 _PTR(SObject) aSO = myStudy->FindObjectID(entry);
152 _PTR(SObject) aRefSObj;
153 GEOM::GEOM_Object_var aShape;
154 // If selected object is a reference
155 if ( aSO->ReferencedObject( aRefSObj )){
156 if (aRefSObj->GetFatherComponent()->ComponentDataType() == "GEOM")
157 aShape=SMESH::SObjectToInterface<GEOM::GEOM_Object>(aRefSObj);
159 // If selected object is a reference is not a reference
161 if ( aSO->GetFatherComponent()->ComponentDataType() == "GEOM")
162 aShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>(aSO);
164 if ( !aShape->_is_nil() ){
165 if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen())
166 S=gen->GeomObjectToShape( aShape.in() );
172 TopAbs_ShapeEnum GeomSelectionTools:: getFirstSelectedShapeType()
174 TopoDS_Shape S=getFirstSelectedTopoDSShape();
176 return S.ShapeType();
178 // FIXME : Gérer l'exception de manière correct si la shape est nulle
183 void GeomSelectionTools::getFaceInformation()
185 TopoDS_Shape S=getFirstSelectedTopoDSShape();
186 if (!S.IsNull() && S.ShapeType()==TopAbs_FACE){
187 TopoDS_Face f=TopoDS::Face(S);
188 Handle(Geom_Surface) surf = BRep_Tool::Surface(f);
189 BRepAdaptor_Surface surf_adap=BRepAdaptor_Surface::BRepAdaptor_Surface(f);
191 /* Global Information */
192 cout << "GLOBAL INFORMATION" << endl;
193 cout << "******************" << endl;
195 buffer << "Degre U : " << surf_adap.UDegree();
196 //conversion nécessaire pour affichage
197 cout << buffer.str() << endl;
198 /* cout << " Degre V : " << surf_adap.VDegree() << endl;
199 cout << " Nb Poles U : " << surf_adap.NbUPoles() << endl;
200 cout << " Nb Poles V : " << surf_adap.NbVPoles() << endl;
201 cout << " Nb Noeuds U : " << surf_adap.NbUKnots() << endl;
202 cout << " Nb Noeuds V : " << surf_adap.NbVKnots() << endl;
203 cout << " U Rationnel ? " << surf_adap.IsURational() << endl;
204 cout << " V Rationnel ? " << surf_adap.IsVRational() << endl; */
206 GeomAbs_SurfaceType surf_type=surf_adap.GetType();
208 Returns the type of the surface : Plane, Cylinder,
209 Cone, Sphere, Torus, BezierSurface,
210 BSplineSurface, SurfaceOfRevolution,
211 SurfaceOfExtrusion, OtherSurface