Salome HOME
[Code coverage FeaturesPlugin]: Improve coverage for Boolean operations
[modules/shaper.git] / src / FeaturesPlugin / Test / TestRotation.py
1 ## Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 ##
3 ## This library is free software; you can redistribute it and/or
4 ## modify it under the terms of the GNU Lesser General Public
5 ## License as published by the Free Software Foundation; either
6 ## version 2.1 of the License, or (at your option) any later version.
7 ##
8 ## This library is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 ## Lesser General Public License for more details.
12 ##
13 ## You should have received a copy of the GNU Lesser General Public
14 ## License along with this library; if not, write to the Free Software
15 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 ##
17 ## See http:##www.salome-platform.org/ or
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 ##
20
21 """
22       TestRotation.py
23       Unit test of FeaturesPlugin_Rotation class
24
25       class FeaturesPlugin_Movement : public ModelAPI_Feature
26         static const std::string MY_ROTATION_ID("Rotation");
27         static const std::string MY_OBJECTS_LIST_ID("main_objects");
28         static const std::string MY_AXIS_OBJECT_ID("axis_object");
29         static const std::string MY_ANGLE_ID("angle");
30
31         data()->addAttribute(OBJECTS_LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
32         data()->addAttribute(AXIS_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
33         data()->addAttribute(ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
34 """
35 #=========================================================================
36 # Initialization of the test
37 #=========================================================================
38 from ModelAPI import *
39 from GeomDataAPI import *
40 from GeomAlgoAPI import *
41 from GeomAPI import *
42 import math
43
44 aSession = ModelAPI_Session.get()
45 aDocument = aSession.moduleDocument()
46 # Create a part for movement
47 aSession.startOperation()
48 aPartFeature = aDocument.addFeature("Part")
49 aSession.finishOperation()
50 assert (len(aPartFeature.results()) == 1)
51 # Another way is:
52 # aPart = aSession.activeDocument()
53 aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
54 aPart = aPartResult.partDoc()
55
56 #=========================================================================
57 # Create a sketch circle to extrude
58 #=========================================================================
59 aSession.startOperation()
60 aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
61 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
62 origin.setValue(0, 0, 0)
63 dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
64 dirx.setValue(1, 0, 0)
65 norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm"))
66 norm.setValue(0, 0, 1)
67 # Create circle
68 aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle")
69 anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
70 aCircleRadius = aSketchCircle.real("circle_radius")
71 anCircleCentr.setValue(50, 50)
72 aCircleRadius.setValue(20)
73 aSession.finishOperation()
74 #=========================================================================
75 # Make extrusion on circle
76 #=========================================================================
77 # Build shape from sketcher results
78 aCircleSketchResult = modelAPI_ResultConstruction(aCircleSketchFeature.firstResult())
79 assert (aCircleSketchResult.facesNum() > 0)
80 # Create extrusion
81 aSession.startOperation()
82 anExtrusionFt = aPart.addFeature("Extrusion")
83 assert (anExtrusionFt.getKind() == "Extrusion")
84 # selection type FACE=4
85 anExtrusionFt.selectionList("base").append(
86     aCircleSketchResult, aCircleSketchResult.face(0))
87 anExtrusionFt.string("CreationMethod").setValue("BySizes")
88 anExtrusionFt.real("to_size").setValue(50)
89 anExtrusionFt.real("from_size").setValue(0)
90 anExtrusionFt.real("to_offset").setValue(0) #TODO: remove
91 anExtrusionFt.real("from_offset").setValue(0) #TODO: remove
92 anExtrusionFt.execute()
93 aSession.finishOperation()
94 assert (anExtrusionFt.real("to_size").value() == 50)
95
96 # Check extrusion results
97 assert (len(anExtrusionFt.results()) > 0)
98 anExtrusionResult = modelAPI_ResultBody(anExtrusionFt.firstResult())
99 assert (anExtrusionResult is not None)
100
101 #=========================================================================
102 # Create a sketch line to rotation
103 #=========================================================================
104 aSession.startOperation()
105 aLineSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
106 origin = geomDataAPI_Point(aLineSketchFeature.attribute("Origin"))
107 origin.setValue(0, 0, 0)
108 dirx = geomDataAPI_Dir(aLineSketchFeature.attribute("DirX"))
109 dirx.setValue(1, 0, 0)
110 norm = geomDataAPI_Dir(aLineSketchFeature.attribute("Norm"))
111 norm.setValue(0, 0, 1)
112
113 aSketchLine = aLineSketchFeature.addFeature("SketchLine")
114 aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
115 aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
116 aLineStartPoint.setValue(-100, -100)
117 aLineEndPoint.setValue(100, -100)
118 aSession.finishOperation()
119
120 # Build shape from sketcher results
121 aLineSketchResult = aLineSketchFeature.firstResult()
122 aLineSketchShape = modelAPI_ResultConstruction(aLineSketchResult).shape()
123 aShapeExplorer = GeomAPI_ShapeExplorer(aLineSketchShape, GeomAPI_Shape.EDGE)
124 aLineEdge = aShapeExplorer.current()
125
126 #=========================================================================
127 # Test rotation
128 #=========================================================================
129 aSession.startOperation()
130 aRotateFt = aPart.addFeature("Rotation")
131 assert (aRotateFt.getKind() == "Rotation")
132 aRotateFt.selectionList("main_objects").append(
133     anExtrusionResult, anExtrusionResult.shape())
134 aRotateFt.string("CreationMethod").setValue("ByAxisAndAngle")
135 aRotateFt.selection("axis_object").setValue(aLineSketchResult, aLineEdge)
136 aRotateFt.real("angle").setValue(90)
137 aRotateFt.execute()
138 aSession.finishOperation()
139 assert (aRotateFt.real("angle").value() == 90)
140
141 # Check rotation results
142 aFactory = ModelAPI_Session.get().validators()
143 assert (aFactory.validate(aRotateFt))
144 assert (len(aRotateFt.results()) > 0)
145 aMoveResult = modelAPI_ResultBody(aRotateFt.firstResult())
146 assert (aMoveResult is not None)
147
148 from salome.shaper import model
149 assert(model.checkPythonDump())