Salome HOME
312fe4b23e7489a4464176cb8d23848f2775f298
[modules/geom.git] / src / GEOMImpl / GEOMImpl_VectorDriver.cxx
1
2 using namespace std;
3 #include "GEOMImpl_VectorDriver.hxx"
4 #include "GEOMImpl_IVector.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOM_Function.hxx"
7
8 #include <BRep_Tool.hxx>
9 #include <BRepBuilderAPI_MakeEdge.hxx>
10
11 #include <TopAbs.hxx>
12 #include <TopoDS.hxx>
13 #include <TopoDS_Shape.hxx>
14 #include <TopoDS_Vertex.hxx>
15
16 #include <gp_Pnt.hxx>
17 #include <Precision.hxx>
18 #include <TCollection_AsciiString.hxx>
19 #include <Standard_ConstructionError.hxx>
20
21 //=======================================================================
22 //function : GetID
23 //purpose  :
24 //=======================================================================
25 const Standard_GUID& GEOMImpl_VectorDriver::GetID()
26 {
27   static Standard_GUID aVectorDriver("FF1BBB04-5D14-4df2-980B-3A668264EA16");
28   return aVectorDriver;
29 }
30
31
32 //=======================================================================
33 //function : GEOMImpl_VectorDriver
34 //purpose  :
35 //=======================================================================
36 GEOMImpl_VectorDriver::GEOMImpl_VectorDriver()
37 {
38 }
39
40 //=======================================================================
41 //function : Execute
42 //purpose  :
43 //=======================================================================
44 Standard_Integer GEOMImpl_VectorDriver::Execute(TFunction_Logbook& log) const
45 {
46   if (Label().IsNull())  return 0;
47   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
48
49   GEOMImpl_IVector aPI (aFunction);
50   Standard_Integer aType = aFunction->GetType();
51   if (aType != VECTOR_DX_DY_DZ && aType != VECTOR_TWO_PNT) return 0;
52
53   TopoDS_Shape aShape;
54
55   if (aType == VECTOR_DX_DY_DZ) {
56     gp_Pnt P1 = gp::Origin();
57     gp_Pnt P2 (aPI.GetDX(), aPI.GetDY(), aPI.GetDZ());
58     if (P1.Distance(P2) < Precision::Confusion()) {
59       TCollection_AsciiString aMsg ("Can not build vector with length, less than ");
60       aMsg += TCollection_AsciiString(Precision::Confusion());
61       Standard_ConstructionError::Raise(aMsg.ToCString());
62     }
63     aShape = BRepBuilderAPI_MakeEdge(P1, P2).Shape();
64   } else if (aType == VECTOR_TWO_PNT) {
65     Handle(GEOM_Function) aRefPnt1 = aPI.GetPoint1();
66     Handle(GEOM_Function) aRefPnt2 = aPI.GetPoint2();
67     TopoDS_Shape aShape1 = aRefPnt1->GetValue();
68     TopoDS_Shape aShape2 = aRefPnt2->GetValue();
69     if (aShape1.ShapeType() != TopAbs_VERTEX ||
70         aShape2.ShapeType() != TopAbs_VERTEX) return 0;
71     if (aShape1.IsSame(aShape2)) {
72       Standard_ConstructionError::Raise("The end points must be different");
73     }
74     gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(aShape1));
75     gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(aShape2));
76     if (P1.Distance(P2) < Precision::Confusion()) {
77       Standard_ConstructionError::Raise("The end points are too close");
78     }
79     aShape = BRepBuilderAPI_MakeEdge(P1, P2).Shape();
80   } else {
81   }
82
83   if (aShape.IsNull()) return 0;
84
85   aFunction->SetValue(aShape);
86
87   log.SetTouched(Label());
88
89   return 1;
90 }
91
92
93 //=======================================================================
94 //function :  GEOMImpl_VectorDriver_Type_
95 //purpose  :
96 //=======================================================================
97 Standard_EXPORT Handle_Standard_Type& GEOMImpl_VectorDriver_Type_()
98 {
99
100   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
101   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
102   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
103   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
104   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
105   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
106
107
108   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
109   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_VectorDriver",
110                                                          sizeof(GEOMImpl_VectorDriver),
111                                                          1,
112                                                          (Standard_Address)_Ancestors,
113                                                          (Standard_Address)NULL);
114
115   return _aType;
116 }
117
118 //=======================================================================
119 //function : DownCast
120 //purpose  :
121 //=======================================================================
122 const Handle(GEOMImpl_VectorDriver) Handle(GEOMImpl_VectorDriver)::DownCast
123        (const Handle(Standard_Transient)& AnObject)
124 {
125   Handle(GEOMImpl_VectorDriver) _anOtherObject;
126
127   if (!AnObject.IsNull()) {
128      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_VectorDriver))) {
129        _anOtherObject = Handle(GEOMImpl_VectorDriver)((Handle(GEOMImpl_VectorDriver)&)AnObject);
130      }
131   }
132
133   return _anOtherObject ;
134 }