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 <GEOMImpl_ScaleDriver.hxx>
24 #include <GEOMImpl_IScale.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOMUtils.hxx>
27 #include <GEOM_Function.hxx>
29 #include <BRepBuilderAPI_Transform.hxx>
30 #include <BRepBuilderAPI_GTransform.hxx>
31 #include <BRep_Tool.hxx>
36 #include <TopoDS_Shape.hxx>
37 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
39 #include <Precision.hxx>
41 #include <gp_Trsf.hxx>
42 #include <gp_GTrsf.hxx>
44 //=======================================================================
47 //=======================================================================
48 const Standard_GUID& GEOMImpl_ScaleDriver::GetID()
50 static Standard_GUID aScaleDriver("FF1BBB52-5D14-4df2-980B-3A668264EA16");
55 //=======================================================================
56 //function : GEOMImpl_ScaleDriver
58 //=======================================================================
59 GEOMImpl_ScaleDriver::GEOMImpl_ScaleDriver()
63 //=======================================================================
66 //=======================================================================
67 Standard_Integer GEOMImpl_ScaleDriver::Execute(LOGBOOK& log) const
69 if (Label().IsNull()) return 0;
70 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
72 GEOMImpl_IScale aCI (aFunction);
73 Standard_Integer aType = aFunction->GetType();
77 if (aType == SCALE_SHAPE || aType == SCALE_SHAPE_COPY) {
78 Handle(GEOM_Function) aRefShape = aCI.GetShape();
79 TopoDS_Shape aShapeBase = aRefShape->GetValue();
80 if (aShapeBase.IsNull()) return 0;
83 Handle(GEOM_Function) aRefPoint = aCI.GetPoint();
84 if (!aRefPoint.IsNull()) {
85 TopoDS_Shape aShapePnt = aRefPoint->GetValue();
86 if (aShapePnt.IsNull()) return 0;
87 if (aShapePnt.ShapeType() != TopAbs_VERTEX) return 0;
88 aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
91 // Bug 6839: Check for standalone (not included in faces) degenerated edges
92 TopTools_IndexedDataMapOfShapeListOfShape aEFMap;
93 TopExp::MapShapesAndAncestors(aShapeBase, TopAbs_EDGE, TopAbs_FACE, aEFMap);
94 Standard_Integer i, nbE = aEFMap.Extent();
95 for (i = 1; i <= nbE; i++) {
96 TopoDS_Shape anEdgeSh = aEFMap.FindKey(i);
97 if (BRep_Tool::Degenerated(TopoDS::Edge(anEdgeSh))) {
98 const TopTools_ListOfShape& aFaces = aEFMap.FindFromIndex(i);
100 Standard_ConstructionError::Raise
101 ("Scaling aborted : cannot scale standalone degenerated edge");
107 aTrsf.SetScale(aP, aCI.GetFactor());
108 BRepBuilderAPI_Transform aBRepTrsf (aShapeBase, aTrsf, Standard_False);
109 aShape = aBRepTrsf.Shape();
111 else if (aType == SCALE_SHAPE_AXES || aType == SCALE_SHAPE_AXES_COPY) {
112 Handle(GEOM_Function) aRefShape = aCI.GetShape();
113 TopoDS_Shape aShapeBase = aRefShape->GetValue();
114 if (aShapeBase.IsNull()) return 0;
118 Handle(GEOM_Function) aRefPoint = aCI.GetPoint();
119 if (!aRefPoint.IsNull()) {
120 TopoDS_Shape aShapePnt = aRefPoint->GetValue();
121 if (aShapePnt.IsNull()) return 0;
122 if (aShapePnt.ShapeType() != TopAbs_VERTEX) return 0;
123 aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
127 // Bug 6839: Check for standalone (not included in faces) degenerated edges
128 TopTools_IndexedDataMapOfShapeListOfShape aEFMap;
129 TopExp::MapShapesAndAncestors(aShapeBase, TopAbs_EDGE, TopAbs_FACE, aEFMap);
130 Standard_Integer i, nbE = aEFMap.Extent();
131 for (i = 1; i <= nbE; i++) {
132 TopoDS_Shape anEdgeSh = aEFMap.FindKey(i);
133 if (BRep_Tool::Degenerated(TopoDS::Edge(anEdgeSh))) {
134 const TopTools_ListOfShape& aFaces = aEFMap.FindFromIndex(i);
135 if (aFaces.IsEmpty())
136 Standard_ConstructionError::Raise
137 ("Scaling aborted : cannot scale standalone degenerated edge");
143 gp_Mat rot (aCI.GetFactorX(), 0, 0,
144 0, aCI.GetFactorY(), 0,
145 0, 0, aCI.GetFactorZ());
146 aGTrsf.SetVectorialPart(rot);
150 if (anO.Distance(aP) > Precision::Confusion()) {
152 aGTrsfP0.SetTranslationPart(anO.XYZ() - aP.XYZ());
154 aGTrsf0P.SetTranslationPart(aP.XYZ());
155 //aGTrsf = aGTrsf0P * aGTrsf * aGTrsfP0;
156 aGTrsf = aGTrsf0P.Multiplied(aGTrsf);
157 aGTrsf = aGTrsf.Multiplied(aGTrsfP0);
161 BRepBuilderAPI_GTransform aBRepGTrsf (aShapeBase, aGTrsf, Standard_False);
162 if (!aBRepGTrsf.IsDone())
163 Standard_ConstructionError::Raise("Scaling not done");
164 aShape = aBRepGTrsf.Shape();
169 if (aShape.IsNull()) return 0;
171 if ( !GEOMUtils::CheckShape(aShape) && !GEOMUtils::FixShapeTolerance(aShape) )
172 Standard_ConstructionError::Raise("Scaling aborted : algorithm has produced an invalid shape result");
174 aFunction->SetValue(aShape);
176 #if OCC_VERSION_MAJOR < 7
177 log.SetTouched(Label());
179 log->SetTouched(Label());
185 //================================================================================
187 * \brief Returns a name of creation operation and names and values of creation parameters
189 //================================================================================
191 bool GEOMImpl_ScaleDriver::
192 GetCreationInformation(std::string& theOperationName,
193 std::vector<GEOM_Param>& theParams)
195 if (Label().IsNull()) return 0;
196 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
198 GEOMImpl_IScale aCI( function );
199 Standard_Integer aType = function->GetType();
201 theOperationName = "SCALE";
205 case SCALE_SHAPE_COPY:
206 AddParam( theParams, "Object", aCI.GetShape() );
207 AddParam( theParams, "Central Point", aCI.GetPoint(), "origin" );
208 AddParam( theParams, "Scale Factor", aCI.GetFactor() );
210 case SCALE_SHAPE_AXES:
211 case SCALE_SHAPE_AXES_COPY:
212 AddParam( theParams, "Object", aCI.GetShape() );
213 AddParam( theParams, "Central Point", aCI.GetPoint(), "origin" );
214 AddParam( theParams, "Scale Factor X", aCI.GetFactorX() );
215 AddParam( theParams, "Scale Factor Y", aCI.GetFactorY() );
216 AddParam( theParams, "Scale Factor Z", aCI.GetFactorZ() );
225 OCCT_IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_ScaleDriver,GEOM_BaseDriver);