Salome HOME
Copyrights update
[modules/geom.git] / src / GEOMImpl / GEOMImpl_ArcDriver.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/
19 //
20
21 #include <Standard_Stream.hxx>
22
23 #include <GEOMImpl_ArcDriver.hxx>
24 #include <GEOMImpl_IArc.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOM_Function.hxx>
27
28 #include <BRepBuilderAPI_MakeEdge.hxx>
29 #include <BRep_Tool.hxx>
30 #include <TopoDS.hxx>
31 #include <TopoDS_Shape.hxx>
32 #include <TopoDS_Edge.hxx>
33 #include <TopoDS_Vertex.hxx>
34 #include <TopAbs.hxx>
35 #include <TopExp.hxx>
36
37 #include <GC_MakeArcOfCircle.hxx>
38
39 #include <Standard_ConstructionError.hxx>
40 #include <Precision.hxx>
41 #include <gp_Pnt.hxx>
42 #include <gp_Vec.hxx>
43
44 //=======================================================================
45 //function : GetID
46 //purpose  :
47 //======================================================================= 
48 const Standard_GUID& GEOMImpl_ArcDriver::GetID()
49 {
50   static Standard_GUID aArcDriver("FF1BBB35-5D14-4df2-980B-3A668264EA16");
51   return aArcDriver; 
52 }
53
54
55 //=======================================================================
56 //function : GEOMImpl_ArcDriver
57 //purpose  : 
58 //=======================================================================
59 GEOMImpl_ArcDriver::GEOMImpl_ArcDriver() 
60 {
61 }
62
63 //=======================================================================
64 //function : Execute
65 //purpose  :
66 //======================================================================= 
67 Standard_Integer GEOMImpl_ArcDriver::Execute(TFunction_Logbook& log) const
68 {
69   if (Label().IsNull()) return 0;    
70   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
71
72   GEOMImpl_IArc aCI (aFunction);
73   Standard_Integer aType = aFunction->GetType();
74
75   TopoDS_Shape aShape;
76
77   if (aType == CIRC_ARC_THREE_PNT) {
78     Handle(GEOM_Function) aRefPoint1 = aCI.GetPoint1();
79     Handle(GEOM_Function) aRefPoint2 = aCI.GetPoint2();
80     Handle(GEOM_Function) aRefPoint3 = aCI.GetPoint3();
81     TopoDS_Shape aShapePnt1 = aRefPoint1->GetValue();
82     TopoDS_Shape aShapePnt2 = aRefPoint2->GetValue();
83     TopoDS_Shape aShapePnt3 = aRefPoint3->GetValue();
84     if (aShapePnt1.ShapeType() == TopAbs_VERTEX &&
85         aShapePnt2.ShapeType() == TopAbs_VERTEX &&
86         aShapePnt3.ShapeType() == TopAbs_VERTEX) {
87       gp_Pnt aP1 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt1));
88       gp_Pnt aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt2));
89       gp_Pnt aP3 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt3));
90       if (aP1.Distance(aP2) < gp::Resolution() ||
91           aP1.Distance(aP3) < gp::Resolution() ||
92           aP2.Distance(aP3) < gp::Resolution())
93         Standard_ConstructionError::Raise("Arc creation aborted: coincident points given");
94       if (gp_Vec(aP1, aP2).IsParallel(gp_Vec(aP1, aP3), Precision::Angular()))
95         Standard_ConstructionError::Raise("Arc creation aborted: points lay on one line");
96       GC_MakeArcOfCircle arc (aP1, aP2, aP3);
97       aShape = BRepBuilderAPI_MakeEdge(arc).Edge();
98     }
99   } else {
100   }
101
102   if (aShape.IsNull()) return 0;
103
104   aFunction->SetValue(aShape);
105
106   log.SetTouched(Label());
107   
108   return 1;    
109 }
110
111
112 //=======================================================================
113 //function :  GEOMImpl_ArcDriver_Type_
114 //purpose  :
115 //======================================================================= 
116 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ArcDriver_Type_()
117 {
118
119   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
120   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
121   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
122   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared); 
123   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
124   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
125  
126
127   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
128   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ArcDriver",
129                                                          sizeof(GEOMImpl_ArcDriver),
130                                                          1,
131                                                          (Standard_Address)_Ancestors,
132                                                          (Standard_Address)NULL);
133
134   return _aType;
135 }
136
137 //=======================================================================
138 //function : DownCast
139 //purpose  :
140 //======================================================================= 
141 const Handle(GEOMImpl_ArcDriver) Handle(GEOMImpl_ArcDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
142 {
143   Handle(GEOMImpl_ArcDriver) _anOtherObject;
144
145   if (!AnObject.IsNull()) {
146      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ArcDriver))) {
147        _anOtherObject = Handle(GEOMImpl_ArcDriver)((Handle(GEOMImpl_ArcDriver)&)AnObject);
148      }
149   }
150
151   return _anOtherObject ;
152 }