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/
20 #include <Standard_Stream.hxx>
22 #include <GEOMImpl_VectorDriver.hxx>
23 #include <GEOMImpl_IVector.hxx>
24 #include <GEOMImpl_Types.hxx>
25 #include <GEOM_Function.hxx>
27 #include <BRep_Tool.hxx>
28 #include <BRepBuilderAPI_MakeEdge.hxx>
32 #include <TopoDS_Shape.hxx>
33 #include <TopoDS_Vertex.hxx>
36 #include <Precision.hxx>
37 #include <TCollection_AsciiString.hxx>
38 #include <Standard_ConstructionError.hxx>
40 //=======================================================================
43 //=======================================================================
44 const Standard_GUID& GEOMImpl_VectorDriver::GetID()
46 static Standard_GUID aVectorDriver("FF1BBB04-5D14-4df2-980B-3A668264EA16");
51 //=======================================================================
52 //function : GEOMImpl_VectorDriver
54 //=======================================================================
55 GEOMImpl_VectorDriver::GEOMImpl_VectorDriver()
59 //=======================================================================
62 //=======================================================================
63 Standard_Integer GEOMImpl_VectorDriver::Execute(TFunction_Logbook& log) const
65 if (Label().IsNull()) return 0;
66 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
68 GEOMImpl_IVector aPI (aFunction);
69 Standard_Integer aType = aFunction->GetType();
70 if (aType != VECTOR_DX_DY_DZ && aType != VECTOR_TWO_PNT) return 0;
74 if (aType == VECTOR_DX_DY_DZ) {
75 gp_Pnt P1 = gp::Origin();
76 gp_Pnt P2 (aPI.GetDX(), aPI.GetDY(), aPI.GetDZ());
77 if (P1.Distance(P2) < Precision::Confusion()) {
78 TCollection_AsciiString aMsg ("Can not build vector with length, less than ");
79 aMsg += TCollection_AsciiString(Precision::Confusion());
80 Standard_ConstructionError::Raise(aMsg.ToCString());
82 aShape = BRepBuilderAPI_MakeEdge(P1, P2).Shape();
83 } else if (aType == VECTOR_TWO_PNT) {
84 Handle(GEOM_Function) aRefPnt1 = aPI.GetPoint1();
85 Handle(GEOM_Function) aRefPnt2 = aPI.GetPoint2();
86 TopoDS_Shape aShape1 = aRefPnt1->GetValue();
87 TopoDS_Shape aShape2 = aRefPnt2->GetValue();
88 if (aShape1.ShapeType() != TopAbs_VERTEX ||
89 aShape2.ShapeType() != TopAbs_VERTEX) return 0;
90 if (aShape1.IsSame(aShape2)) {
91 Standard_ConstructionError::Raise("The end points must be different");
93 TopoDS_Vertex V1 = TopoDS::Vertex(aShape1);
94 TopoDS_Vertex V2 = TopoDS::Vertex(aShape2);
95 gp_Pnt P1 = BRep_Tool::Pnt(V1);
96 gp_Pnt P2 = BRep_Tool::Pnt(V2);
97 if (P1.Distance(P2) < Precision::Confusion()) {
98 Standard_ConstructionError::Raise("The end points are too close");
100 aShape = BRepBuilderAPI_MakeEdge(V1, V2).Shape();
104 if (aShape.IsNull()) return 0;
106 aFunction->SetValue(aShape);
108 log.SetTouched(Label());
114 //=======================================================================
115 //function : GEOMImpl_VectorDriver_Type_
117 //=======================================================================
118 Standard_EXPORT Handle_Standard_Type& GEOMImpl_VectorDriver_Type_()
121 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
122 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
123 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
124 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
125 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
126 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
129 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
130 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_VectorDriver",
131 sizeof(GEOMImpl_VectorDriver),
133 (Standard_Address)_Ancestors,
134 (Standard_Address)NULL);
139 //=======================================================================
140 //function : DownCast
142 //=======================================================================
143 const Handle(GEOMImpl_VectorDriver) Handle(GEOMImpl_VectorDriver)::DownCast
144 (const Handle(Standard_Transient)& AnObject)
146 Handle(GEOMImpl_VectorDriver) _anOtherObject;
148 if (!AnObject.IsNull()) {
149 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_VectorDriver))) {
150 _anOtherObject = Handle(GEOMImpl_VectorDriver)((Handle(GEOMImpl_VectorDriver)&)AnObject);
154 return _anOtherObject ;