1 # Copyright (C) 2020-2021 CEA/DEN, EDF R&D
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.
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.
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
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 Test projection without the reference to the source geometry.
26 from salome.shaper import model
28 from ModelAPI import *
30 __updated__ = "2020-07-07"
35 class TestProjectionWithoutRef(unittest.TestCase):
38 self.myDocument = model.moduleDocument()
39 self.mySketch = model.addSketch(partSet, model.selection("FACE", PLANE.name()))
46 self.myNbEllipticArcs = 2
48 self.myNbPeriodicSplines = 1
49 self.myNbProjections = 0
50 self.myNbFixedConstraints = 0
51 self.myNbEdgesInSketch = 0
56 model.testNbSubFeatures(self.mySketch, "SketchPoint", self.myNbPoints)
57 model.testNbSubFeatures(self.mySketch, "SketchLine", self.myNbLines)
58 model.testNbSubFeatures(self.mySketch, "SketchCircle", self.myNbCircles)
59 model.testNbSubFeatures(self.mySketch, "SketchArc", self.myNbArcs)
60 model.testNbSubFeatures(self.mySketch, "SketchEllipse", self.myNbEllipses)
61 model.testNbSubFeatures(self.mySketch, "SketchEllipticArc", self.myNbEllipticArcs)
62 model.testNbSubFeatures(self.mySketch, "SketchBSpline", self.myNbSplines)
63 model.testNbSubFeatures(self.mySketch, "SketchBSplinePeriodic", self.myNbPeriodicSplines)
64 model.testNbSubFeatures(self.mySketch, "SketchProjection", self.myNbProjections)
65 model.testNbSubFeatures(self.mySketch, "SketchConstraintRigid", self.myNbFixedConstraints)
67 exp = GeomAPI_ShapeExplorer(self.mySketch.defaultResult().shape(), GeomAPI_Shape.EDGE)
68 while exp.more(): nbEdges += 1; exp.next()
69 self.assertEqual(self.myNbEdgesInSketch, nbEdges)
72 self.assertEqual(model.dof(self.mySketch), self.myDOF)
75 def test_projection_withref_includeintoresult(self):
76 """ Test 1. Projection with the reference to the original shapes. Projected curves are composed into the sketch result.
79 self.mySketch.addProjection(c, keepResult = True)
80 self.myNbProjections = len(CURVES)
81 self.myNbEdgesInSketch = len(CURVES) - 1
83 def test_projection_withref_notincludeintoresult(self):
84 """ Test 2. Projection with the reference to the original shapes. Projected curves are NOT included into the sketch result.
87 self.mySketch.addProjection(c, keepResult = False)
88 self.myNbProjections = len(CURVES)
90 def test_projection_withoutref_noconstraints(self):
91 """ Test 3. Projection without the reference to the original shapes. No additional constraints applied.
94 self.mySketch.addProjection(c, keepRefToOriginal = False)
96 self.myNbEdgesInSketch = len(CURVES) - 1
97 self.myDOF += 2 + 4 + 5 + 7 + 5 + 7 + 6 * 2 + 6 * 2
99 def test_projection_withoutref_fixed(self):
100 """ Test 4. Projection without the reference to the original shapes. Additionally, Fixed constraints applied.
103 # use the low-level API to access the necessary attributes
104 session = ModelAPI_Session.get()
106 session.startOperation()
107 proj = featureToCompositeFeature(self.mySketch.feature()).addFeature("SketchProjection")
108 proj.boolean("IncludeToResult").setValue(False)
109 proj.string("keep_reference").setValue("False")
110 proj.boolean("make_fixed").setValue(True)
111 c.fillAttribute(proj.selection("ExternalFeature"))
112 session.finishOperation()
113 self.myNbEdgesInSketch = len(CURVES) - 1
114 self.myNbFixedConstraints = len(CURVES)
118 if __name__ == "__main__":
120 partSet = model.moduleDocument()
121 Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY"))
122 SketchPoint_1 = Sketch_1.addPoint(35, -40)
123 CURVES.append(model.selection("VERTEX", Sketch_1.name() + "/" + SketchPoint_1.name()))
124 SketchLine_1 = Sketch_1.addLine(20, -15, 40, 15)
125 CURVES.append(model.selection("EDGE", Sketch_1.name() + "/" + SketchLine_1.name()))
126 SketchCircle_1 = Sketch_1.addCircle(65, -30, 20)
127 CURVES.append(model.selection("EDGE", Sketch_1.name() + "/" + SketchCircle_1.defaultResult().data().name()))
128 SketchArc_1 = Sketch_1.addArc(60, 15, 80, 0, 50, 33, False)
129 CURVES.append(model.selection("EDGE", Sketch_1.name() + "/" + SketchArc_1.defaultResult().data().name()))
130 SketchEllipse_1 = Sketch_1.addEllipse(25, 30, 40, 30, 10)
131 CURVES.append(model.selection("EDGE", Sketch_1.name() + "/" + SketchEllipse_1.defaultResult().data().name()))
132 SketchEllipticArc_1 = Sketch_1.addEllipticArc(40, 70, 55, 70, 45, 50, 25, 56, False)
133 CURVES.append(model.selection("EDGE", Sketch_1.name() + "/" + SketchEllipticArc_1.defaultResult().data().name()))
134 SketchBSpline_1_poles = [(95, -50), (130, -10), (100, 10), (125, 45), (90, 70), (55, 45)]
135 SketchBSpline_1 = Sketch_1.addSpline(poles = SketchBSpline_1_poles)
136 CURVES.append(model.selection("EDGE", Sketch_1.name() + "/" + SketchBSpline_1.name()))
137 SketchBSplinePeriodic_1_poles = [(95, 80), (135, 90), (145, 55), (130, 30), (125, 70), (105, 60)]
138 SketchBSplinePeriodic_1 = Sketch_1.addSpline(poles = SketchBSplinePeriodic_1_poles, periodic = True)
139 CURVES.append(model.selection("EDGE", Sketch_1.name() + "/" + SketchBSplinePeriodic_1.name()))
141 PLANE = model.addPlane(partSet, model.selection("FACE", "XOY"), model.selection("EDGE", "OY"), 45)
144 test_program = unittest.main(exit=False)
145 assert test_program.result.wasSuccessful(), "Test failed"
146 assert model.checkPythonDump()