]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMImpl/GEOMImpl_LineDriver.cxx
Salome HOME
Continue bug 10627 fixing: guarantee non-regression behaviour, applying ShapeFix_Wire...
[modules/geom.git] / src / GEOMImpl / GEOMImpl_LineDriver.cxx
1
2 #include <Standard_Stream.hxx>
3
4 #include <GEOMImpl_LineDriver.hxx>
5 #include <GEOMImpl_ILine.hxx>
6 #include <GEOMImpl_Types.hxx>
7 #include <GEOM_Function.hxx>
8
9 #include <BRep_Tool.hxx>
10 #include <BRepBuilderAPI_MakeEdge.hxx>
11
12 #include <TopAbs.hxx>
13 #include <TopExp.hxx>
14 #include <TopoDS.hxx>
15 #include <TopoDS_Edge.hxx>
16 #include <TopoDS_Shape.hxx>
17 #include <TopoDS_Vertex.hxx>
18
19 #include <gp_Pnt.hxx>
20 #include <Precision.hxx>
21 #include <Standard_ConstructionError.hxx>
22 #include <Standard_NullObject.hxx>
23
24 //=======================================================================
25 //function : GetID
26 //purpose  :
27 //=======================================================================
28 const Standard_GUID& GEOMImpl_LineDriver::GetID()
29 {
30   static Standard_GUID aLineDriver("FF1BBB06-5D14-4df2-980B-3A668264EA16");
31   return aLineDriver;
32 }
33
34
35 //=======================================================================
36 //function : GEOMImpl_LineDriver
37 //purpose  :
38 //=======================================================================
39 GEOMImpl_LineDriver::GEOMImpl_LineDriver()
40 {
41 }
42
43 //=======================================================================
44 //function : Execute
45 //purpose  :
46 //=======================================================================
47 Standard_Integer GEOMImpl_LineDriver::Execute(TFunction_Logbook& log) const
48 {
49   if (Label().IsNull())  return 0;
50   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
51
52   GEOMImpl_ILine aPI (aFunction);
53   Standard_Integer aType = aFunction->GetType();
54
55   TopoDS_Shape aShape;
56
57   if (aType == LINE_TWO_PNT) {
58     Handle(GEOM_Function) aRefPnt1 = aPI.GetPoint1();
59     Handle(GEOM_Function) aRefPnt2 = aPI.GetPoint2();
60     TopoDS_Shape aShape1 = aRefPnt1->GetValue();
61     TopoDS_Shape aShape2 = aRefPnt2->GetValue();
62     if (aShape1.ShapeType() != TopAbs_VERTEX ||
63         aShape2.ShapeType() != TopAbs_VERTEX) return 0;
64     if (aShape1.IsSame(aShape2)) {
65       Standard_ConstructionError::Raise("The end points must be different");
66     }
67     gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(aShape1));
68     gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(aShape2));
69     if (P1.Distance(P2) < Precision::Confusion()) {
70       Standard_ConstructionError::Raise("The end points are too close");
71     }
72     aShape = BRepBuilderAPI_MakeEdge(P1, P2).Shape();
73
74   } else if (aType == LINE_PNT_DIR) {
75     Handle(GEOM_Function) aRefPnt = aPI.GetPoint1();
76     Handle(GEOM_Function) aRefDir = aPI.GetPoint2();
77     TopoDS_Shape aShape1 = aRefPnt->GetValue();
78     TopoDS_Shape aShape2 = aRefDir->GetValue();
79     if (aShape1.ShapeType() != TopAbs_VERTEX ||
80         aShape2.ShapeType() != TopAbs_EDGE) return 0;
81     if (aShape1.IsSame(aShape2)) {
82       Standard_ConstructionError::Raise("The end points must be different");
83     }
84     gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(aShape1));
85
86     TopoDS_Edge anE = TopoDS::Edge(aShape2);
87     TopoDS_Vertex V1, V2;
88     TopExp::Vertices(anE, V1, V2, Standard_True);
89     if (V1.IsNull() || V2.IsNull()) {
90       Standard_NullObject::Raise("Line creation aborted: vector is not defined");
91     }
92     gp_Pnt PV1 = BRep_Tool::Pnt(V1);
93     gp_Pnt PV2 = BRep_Tool::Pnt(V2);
94     if (PV1.Distance(PV2) < Precision::Confusion()) {
95       Standard_ConstructionError::Raise("Vector with null magnitude");
96     }
97
98     gp_Pnt P2 (P1.XYZ() + PV2.XYZ() - PV1.XYZ());
99     aShape = BRepBuilderAPI_MakeEdge(P1, P2).Shape();
100   } else {
101   }
102
103   if (aShape.IsNull()) return 0;
104   aShape.Infinite(true);
105
106   aFunction->SetValue(aShape);
107
108   log.SetTouched(Label());
109
110   return 1;
111 }
112
113
114 //=======================================================================
115 //function :  GEOMImpl_LineDriver_Type_
116 //purpose  :
117 //=======================================================================
118 Standard_EXPORT Handle_Standard_Type& GEOMImpl_LineDriver_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_LineDriver",
131                                                          sizeof(GEOMImpl_LineDriver),
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_LineDriver) Handle(GEOMImpl_LineDriver)::DownCast
144        (const Handle(Standard_Transient)& AnObject)
145 {
146   Handle(GEOMImpl_LineDriver) _anOtherObject;
147
148   if (!AnObject.IsNull()) {
149      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_LineDriver))) {
150        _anOtherObject = Handle(GEOMImpl_LineDriver)((Handle(GEOMImpl_LineDriver)&)AnObject);
151      }
152   }
153
154   return _anOtherObject ;
155 }