]> SALOME platform Git repositories - plugins/blsurfplugin.git/blob - src/PluginUtils/GeomSelectionTools.cxx
Salome HOME
First version of SizeMap for BLSurf :
[plugins/blsurfplugin.git] / src / PluginUtils / GeomSelectionTools.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // ---
20 // File    : GeomSelectionTools.cxx
21 // Authors : Nicolas GEIMER (OCC)
22 // ---
23 //
24
25
26 #include "GeomSelectionTools.h"
27 #include <sstream>
28
29 #include <LightApp_SelectionMgr.h> 
30 #include <SalomeApp_Application.h> 
31 #include <SUIT_Session.h> 
32
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> 
38
39 #include <TopoDS.hxx>
40 #include <BRep_Tool.hxx>
41 #include <Handle_Geom_Surface.hxx>
42 #include <BRepAdaptor_Surface.hxx>
43 #include <GeomAbs_SurfaceType.hxx>
44
45 GeomSelectionTools::GeomSelectionTools(_PTR(Study) aStudy)
46 {
47   myStudy = aStudy;
48 }
49   
50
51
52 LightApp_SelectionMgr*  GeomSelectionTools::selectionMgr()
53 {
54   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
55   if (anApp)
56     return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() ); 
57   else  
58     return 0;
59 }
60  
61 SALOME_ListIO* GeomSelectionTools::getSelectedSalomeObjects()
62 {
63   SALOME_ListIO* selected;
64   LightApp_SelectionMgr* aSel = selectionMgr();
65   aSel->selectedObjects( *selected, NULL, false );
66   return selected;
67 }
68
69
70 Handle(SALOME_InteractiveObject) GeomSelectionTools::getFirstSelectedSalomeObject()
71 {
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;
78     anIO = anIt.Value();
79     return anIO;
80   }
81   return NULL;
82 }
83
84 std::string GeomSelectionTools::getFirstSelectedEntry()
85 {
86   Handle(SALOME_InteractiveObject) anIO;
87   std::string entry="";
88   anIO=GeomSelectionTools::getFirstSelectedSalomeObject();
89   return GeomSelectionTools::getEntryOfObject(anIO);
90 }
91
92 std::string GeomSelectionTools::getEntryOfObject(Handle(SALOME_InteractiveObject) anIO){
93   std::string entry="";
94   _PTR(SObject) aSO = myStudy->FindObjectID(anIO->getEntry());
95   if (aSO){   
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
101     else
102       entry= anIO->getEntry();
103   }
104   return entry;
105 }
106   
107
108 std::string GeomSelectionTools::getNameFromEntry(std::string entry){
109   std::string name = "";
110   _PTR(SObject) aSO = myStudy->FindObjectID(entry);
111   if (aSO){
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
117     else
118       name = aSO->GetName();
119    }
120   return name;
121 }
122
123 std::string GeomSelectionTools::getFirstSelectedComponentDataType()
124 {
125   Handle(SALOME_InteractiveObject) anIO;
126   std::string DataType="";
127   anIO=GeomSelectionTools::getFirstSelectedSalomeObject();
128   _PTR(SObject) aSO = myStudy->FindObjectID(anIO->getEntry()); 
129   if (aSO){
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 
135     else 
136       DataType=anIO->getComponentDataType();
137  }
138  return DataType;
139 }
140
141 TopoDS_Shape GeomSelectionTools::getFirstSelectedTopoDSShape()
142 {
143  Handle(SALOME_InteractiveObject) anIO;
144  anIO=GeomSelectionTools::getFirstSelectedSalomeObject();
145  return entryToShape(anIO->getEntry());
146 }
147
148 TopoDS_Shape GeomSelectionTools::entryToShape(std::string entry){
149   TopoDS_Shape S = TopoDS_Shape();
150    _PTR(SObject) aSO = myStudy->FindObjectID(entry);
151   if (aSO){ 
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);
158      }
159      // If selected object is a reference is not a reference
160      else {
161        if (  aSO->GetFatherComponent()->ComponentDataType() == "GEOM") 
162          aShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>(aSO);
163      }
164      if ( !aShape->_is_nil() ){
165        if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen())
166           S=gen->GeomObjectToShape( aShape.in() );
167     }
168   }
169   return S;
170 }
171
172 TopAbs_ShapeEnum GeomSelectionTools:: getFirstSelectedShapeType()
173 {
174  TopoDS_Shape S=getFirstSelectedTopoDSShape();
175  if (!S.IsNull())
176    return S.ShapeType();
177  else
178    // FIXME : Gérer l'exception de manière correct si la shape est nulle
179    return TopAbs_SHAPE;
180
181 }
182
183 void GeomSelectionTools::getFaceInformation()
184 {
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);
190     
191     /* Global Information */
192     cout << "GLOBAL INFORMATION" << endl;
193     cout << "******************" << endl;
194     stringstream buffer;
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; */
205
206     GeomAbs_SurfaceType surf_type=surf_adap.GetType();
207     /*
208     Returns the type of the surface : Plane, Cylinder,
209     Cone, Sphere, Torus, BezierSurface,
210     BSplineSurface, SurfaceOfRevolution,
211     SurfaceOfExtrusion, OtherSurface 
212     */
213     
214     
215     
216   }
217   return;
218 }