Salome HOME
Copyrights update
[modules/geom.git] / src / GEOMImpl / GEOMImpl_VectorDriver.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 #include <Standard_Stream.hxx>
21
22 #include <GEOMImpl_VectorDriver.hxx>
23 #include <GEOMImpl_IVector.hxx>
24 #include <GEOMImpl_Types.hxx>
25 #include <GEOM_Function.hxx>
26
27 #include <BRep_Tool.hxx>
28 #include <BRepBuilderAPI_MakeEdge.hxx>
29
30 #include <TopAbs.hxx>
31 #include <TopoDS.hxx>
32 #include <TopoDS_Shape.hxx>
33 #include <TopoDS_Vertex.hxx>
34
35 #include <gp_Pnt.hxx>
36 #include <Precision.hxx>
37 #include <TCollection_AsciiString.hxx>
38 #include <Standard_ConstructionError.hxx>
39
40 //=======================================================================
41 //function : GetID
42 //purpose  :
43 //=======================================================================
44 const Standard_GUID& GEOMImpl_VectorDriver::GetID()
45 {
46   static Standard_GUID aVectorDriver("FF1BBB04-5D14-4df2-980B-3A668264EA16");
47   return aVectorDriver;
48 }
49
50
51 //=======================================================================
52 //function : GEOMImpl_VectorDriver
53 //purpose  :
54 //=======================================================================
55 GEOMImpl_VectorDriver::GEOMImpl_VectorDriver()
56 {
57 }
58
59 //=======================================================================
60 //function : Execute
61 //purpose  :
62 //=======================================================================
63 Standard_Integer GEOMImpl_VectorDriver::Execute(TFunction_Logbook& log) const
64 {
65   if (Label().IsNull())  return 0;
66   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
67
68   GEOMImpl_IVector aPI (aFunction);
69   Standard_Integer aType = aFunction->GetType();
70   if (aType != VECTOR_DX_DY_DZ && aType != VECTOR_TWO_PNT) return 0;
71
72   TopoDS_Shape aShape;
73
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());
81     }
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");
92     }
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");
99     }
100     aShape = BRepBuilderAPI_MakeEdge(V1, V2).Shape();
101   } else {
102   }
103
104   if (aShape.IsNull()) return 0;
105
106   aFunction->SetValue(aShape);
107
108   log.SetTouched(Label());
109
110   return 1;
111 }
112
113
114 //=======================================================================
115 //function :  GEOMImpl_VectorDriver_Type_
116 //purpose  :
117 //=======================================================================
118 Standard_EXPORT Handle_Standard_Type& GEOMImpl_VectorDriver_Type_()
119 {
120
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);
127
128
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),
132                                                          1,
133                                                          (Standard_Address)_Ancestors,
134                                                          (Standard_Address)NULL);
135
136   return _aType;
137 }
138
139 //=======================================================================
140 //function : DownCast
141 //purpose  :
142 //=======================================================================
143 const Handle(GEOMImpl_VectorDriver) Handle(GEOMImpl_VectorDriver)::DownCast
144        (const Handle(Standard_Transient)& AnObject)
145 {
146   Handle(GEOMImpl_VectorDriver) _anOtherObject;
147
148   if (!AnObject.IsNull()) {
149      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_VectorDriver))) {
150        _anOtherObject = Handle(GEOMImpl_VectorDriver)((Handle(GEOMImpl_VectorDriver)&)AnObject);
151      }
152   }
153
154   return _anOtherObject ;
155 }