1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/
21 #include <Standard_Stream.hxx>
23 #include <GEOMImpl_LineDriver.hxx>
24 #include <GEOMImpl_ILine.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOM_Function.hxx>
28 #include <BRep_Tool.hxx>
29 #include <BRepBuilderAPI_MakeEdge.hxx>
34 #include <TopoDS_Edge.hxx>
35 #include <TopoDS_Shape.hxx>
36 #include <TopoDS_Vertex.hxx>
39 #include <Precision.hxx>
40 #include <Standard_ConstructionError.hxx>
41 #include <Standard_NullObject.hxx>
43 //=======================================================================
46 //=======================================================================
47 const Standard_GUID& GEOMImpl_LineDriver::GetID()
49 static Standard_GUID aLineDriver("FF1BBB06-5D14-4df2-980B-3A668264EA16");
54 //=======================================================================
55 //function : GEOMImpl_LineDriver
57 //=======================================================================
58 GEOMImpl_LineDriver::GEOMImpl_LineDriver()
62 //=======================================================================
65 //=======================================================================
66 Standard_Integer GEOMImpl_LineDriver::Execute(TFunction_Logbook& log) const
68 if (Label().IsNull()) return 0;
69 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
71 GEOMImpl_ILine aPI (aFunction);
72 Standard_Integer aType = aFunction->GetType();
76 if (aType == LINE_TWO_PNT) {
77 Handle(GEOM_Function) aRefPnt1 = aPI.GetPoint1();
78 Handle(GEOM_Function) aRefPnt2 = aPI.GetPoint2();
79 TopoDS_Shape aShape1 = aRefPnt1->GetValue();
80 TopoDS_Shape aShape2 = aRefPnt2->GetValue();
81 if (aShape1.ShapeType() != TopAbs_VERTEX ||
82 aShape2.ShapeType() != TopAbs_VERTEX) return 0;
83 if (aShape1.IsSame(aShape2)) {
84 Standard_ConstructionError::Raise("The end points must be different");
86 gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(aShape1));
87 gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(aShape2));
88 if (P1.Distance(P2) < Precision::Confusion()) {
89 Standard_ConstructionError::Raise("The end points are too close");
91 aShape = BRepBuilderAPI_MakeEdge(P1, P2).Shape();
93 } else if (aType == LINE_PNT_DIR) {
94 Handle(GEOM_Function) aRefPnt = aPI.GetPoint1();
95 Handle(GEOM_Function) aRefDir = aPI.GetPoint2();
96 TopoDS_Shape aShape1 = aRefPnt->GetValue();
97 TopoDS_Shape aShape2 = aRefDir->GetValue();
98 if (aShape1.ShapeType() != TopAbs_VERTEX ||
99 aShape2.ShapeType() != TopAbs_EDGE) return 0;
100 if (aShape1.IsSame(aShape2)) {
101 Standard_ConstructionError::Raise("The end points must be different");
103 gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(aShape1));
105 TopoDS_Edge anE = TopoDS::Edge(aShape2);
106 TopoDS_Vertex V1, V2;
107 TopExp::Vertices(anE, V1, V2, Standard_True);
108 if (V1.IsNull() || V2.IsNull()) {
109 Standard_NullObject::Raise("Line creation aborted: vector is not defined");
111 gp_Pnt PV1 = BRep_Tool::Pnt(V1);
112 gp_Pnt PV2 = BRep_Tool::Pnt(V2);
113 if (PV1.Distance(PV2) < Precision::Confusion()) {
114 Standard_ConstructionError::Raise("Vector with null magnitude");
117 gp_Pnt P2 (P1.XYZ() + PV2.XYZ() - PV1.XYZ());
118 aShape = BRepBuilderAPI_MakeEdge(P1, P2).Shape();
122 if (aShape.IsNull()) return 0;
123 aShape.Infinite(true);
125 aFunction->SetValue(aShape);
127 log.SetTouched(Label());
133 //=======================================================================
134 //function : GEOMImpl_LineDriver_Type_
136 //=======================================================================
137 Standard_EXPORT Handle_Standard_Type& GEOMImpl_LineDriver_Type_()
140 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
141 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
142 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
143 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
144 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
145 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
148 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
149 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_LineDriver",
150 sizeof(GEOMImpl_LineDriver),
152 (Standard_Address)_Ancestors,
153 (Standard_Address)NULL);
158 //=======================================================================
159 //function : DownCast
161 //=======================================================================
162 const Handle(GEOMImpl_LineDriver) Handle(GEOMImpl_LineDriver)::DownCast
163 (const Handle(Standard_Transient)& AnObject)
165 Handle(GEOMImpl_LineDriver) _anOtherObject;
167 if (!AnObject.IsNull()) {
168 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_LineDriver))) {
169 _anOtherObject = Handle(GEOMImpl_LineDriver)((Handle(GEOMImpl_LineDriver)&)AnObject);
173 return _anOtherObject ;