1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <Standard_Stream.hxx>
25 #include <GEOMImpl_MarkerDriver.hxx>
26 #include <GEOMImpl_IMarker.hxx>
27 #include <GEOMImpl_Types.hxx>
29 #include <GEOM_Function.hxx>
31 #include <GEOMUtils.hxx>
33 #include <BRepBuilderAPI_MakeFace.hxx>
34 #include <BRep_Tool.hxx>
38 #include <TopoDS_Shape.hxx>
39 #include <TopoDS_Edge.hxx>
40 #include <TopoDS_Vertex.hxx>
43 #include <GC_MakePlane.hxx>
44 #include <Geom_Surface.hxx>
46 #include <Precision.hxx>
52 #include <Standard_ConstructionError.hxx>
54 //=======================================================================
57 //=======================================================================
58 const Standard_GUID& GEOMImpl_MarkerDriver::GetID()
60 static Standard_GUID aMarkerDriver("FF1BBB07-5D14-4df2-980B-3A668264EA16");
65 //=======================================================================
66 //function : GEOMImpl_MarkerDriver
68 //=======================================================================
69 GEOMImpl_MarkerDriver::GEOMImpl_MarkerDriver()
73 //=======================================================================
76 //=======================================================================
77 Standard_Integer GEOMImpl_MarkerDriver::Execute(LOGBOOK& log) const
79 if (Label().IsNull()) return 0;
80 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
82 GEOMImpl_IMarker aPI (aFunction);
83 Standard_Integer aType = aFunction->GetType();
87 if (aType == MARKER_CS) {
91 aPI.GetOrigin(OX, OY, OZ);
92 aPI.GetXDir(XDX, XDY, XDZ);
93 aPI.GetYDir(YDX, YDY, YDZ);
95 gp_Pnt aPO (OX, OY, OZ);
96 gp_Vec aVX (XDX, XDY, XDZ);
97 gp_Vec aVY (YDX, YDY, YDZ);
98 Standard_Real aTol = Precision::Confusion();
99 if (aVX.Magnitude() < aTol ||
100 aVY.Magnitude() < aTol ||
101 aVX.IsParallel(aVY, Precision::Angular())) {
102 Standard_ConstructionError::Raise("Degenerated or parallel directions given");
105 gp_Vec aN = aVX ^ aVY;
106 gp_Ax3 anA (aPO, aN, aVX);
109 double aTrimSize = 100.0;
110 aShape = BRepBuilderAPI_MakeFace(aPln, -aTrimSize, +aTrimSize, -aTrimSize, +aTrimSize).Shape();
111 } else if (aType == MARKER_SHAPE) {
112 Handle(GEOM_Function) aRefShape = aPI.GetShape();
113 TopoDS_Shape aSh = aRefShape->GetValue();
114 gp_Ax3 anAx3 = GEOMUtils::GetPosition(aSh);
117 double aTrimSize = 100.0;
118 aShape = BRepBuilderAPI_MakeFace(aPln, -aTrimSize, +aTrimSize, -aTrimSize, +aTrimSize).Shape();
119 } else if (aType == MARKER_PNT2VEC) {
120 Handle(GEOM_Function) aRefOrigin = aPI.GetOrigin();
121 Handle(GEOM_Function) aRefXVec = aPI.GetXVec();
122 Handle(GEOM_Function) aRefYVec = aPI.GetYVec();
123 TopoDS_Shape aShapeOrigin = aRefOrigin->GetValue();
124 TopoDS_Shape aShapeXVec = aRefXVec->GetValue();
125 TopoDS_Shape aShapeYVec = aRefYVec->GetValue();
126 if (aShapeOrigin.ShapeType() != TopAbs_VERTEX || aShapeOrigin.IsNull()) return 0;
127 if (aShapeXVec.ShapeType() != TopAbs_EDGE || aShapeXVec.IsNull()) return 0;
128 if (aShapeYVec.ShapeType() != TopAbs_EDGE || aShapeYVec.IsNull()) return 0;
130 gp_Pnt aPO = BRep_Tool::Pnt( TopoDS::Vertex( aShapeOrigin ) );
132 gp_Pnt aPX1 = BRep_Tool::Pnt( TopExp::FirstVertex( TopoDS::Edge( aShapeXVec ) ) );
133 gp_Pnt aPX2 = BRep_Tool::Pnt( TopExp::LastVertex( TopoDS::Edge( aShapeXVec ) ) );
134 gp_Vec aVX( aPX1, aPX2 );
136 gp_Pnt aPY1 = BRep_Tool::Pnt( TopExp::FirstVertex( TopoDS::Edge( aShapeYVec ) ) );
137 gp_Pnt aPY2 = BRep_Tool::Pnt( TopExp::LastVertex( TopoDS::Edge( aShapeYVec ) ) );
138 gp_Vec aVY( aPY1, aPY2 );
140 if (aVX.Magnitude() < gp::Resolution() || aVY.Magnitude() < gp::Resolution())
141 Standard_ConstructionError::Raise
142 ("Local CS creation aborted: vector of zero length is given");
144 if ( aVX.IsParallel(aVY, Precision::Angular()))
145 Standard_ConstructionError::Raise("Parallel Vectors given");
147 gp_Vec aN = aVX ^ aVY;
148 gp_Ax3 anA (aPO, aN, aVX);
151 double aTrimSize = 100.0;
152 aShape = BRepBuilderAPI_MakeFace(aPln, -aTrimSize, +aTrimSize, -aTrimSize, +aTrimSize).Shape();
156 if (aShape.IsNull()) return 0;
158 aFunction->SetValue(aShape);
160 #if OCC_VERSION_MAJOR < 7
161 log.SetTouched(Label());
163 log->SetTouched(Label());
169 //================================================================================
171 * \brief Returns a name of creation operation and names and values of creation parameters
173 //================================================================================
175 bool GEOMImpl_MarkerDriver::
176 GetCreationInformation(std::string& theOperationName,
177 std::vector<GEOM_Param>& theParams)
179 if (Label().IsNull()) return 0;
180 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
182 GEOMImpl_IMarker aCI( function );
183 Standard_Integer aType = function->GetType();
185 theOperationName = "LOCAL_CS";
190 double OX,OY,OZ, XDX,XDY,XDZ, YDX,YDY,YDZ;
191 aCI.GetOrigin(OX, OY, OZ);
192 aCI.GetXDir(XDX, XDY, XDZ);
193 aCI.GetYDir(YDX, YDY, YDZ);
194 AddParam( theParams, "Coordinates of origin" ) << OX << ", " << OY << ", " << OZ;
195 AddParam( theParams, "X axis direction" ) << XDX << ", " << XDY << ", " << XDZ;
196 AddParam( theParams, "Y axis direction" ) << YDX << ", " << YDY << ", " << YDZ;
200 AddParam( theParams, "Object", aCI.GetShape() );
203 AddParam( theParams, "Point", aCI.GetOrigin() );
204 AddParam( theParams, "X axis direction", aCI.GetXVec() );
205 AddParam( theParams, "Y axis direction", aCI.GetYVec() );
214 OCCT_IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_MarkerDriver,GEOM_BaseDriver);