1 # GEOM GEOM_SWIG : binding of C++ implementaion with Python
3 # Copyright (C) 2003 CEA
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # See http://www.salome-platform.org or email : webmaster.salome@opencascade.org
22 # File : GEOM_TestOthers.py
23 # Author : Julia DOROVSKIKH
27 def TestOtherOperations (geompy, math):
30 p11 = geompy.MakeVertex( 0, 0, 0)
31 p12 = geompy.MakeVertex(30, 0, 0)
32 p13 = geompy.MakeVertex(30, 30, 0)
33 p14 = geompy.MakeVertex( 0, 30, 0)
35 p21 = geompy.MakeVertex(10, 10, 0)
36 p22 = geompy.MakeVertex(20, 10, 0)
37 p23 = geompy.MakeVertex(20, 20, 0)
38 p24 = geompy.MakeVertex(10, 20, 0)
40 e11 = geompy.MakeEdge(p11, p12)
41 e12 = geompy.MakeEdge(p12, p13)
42 e13 = geompy.MakeEdge(p13, p14)
43 e14 = geompy.MakeEdge(p14, p11)
45 e21 = geompy.MakeEdge(p21, p22)
46 e22 = geompy.MakeEdge(p22, p23)
47 e23 = geompy.MakeEdge(p23, p24)
48 e24 = geompy.MakeEdge(p24, p21)
50 w1 = geompy.MakeWire([e11, e12, e13, e14])
51 w2 = geompy.MakeWire([e21, e22, e23, e24])
52 w3 = geompy.MakeTranslation(w2, 0, 0, 10)
54 id_w1 = geompy.addToStudy(w1, "Outside Wire")
55 id_w2 = geompy.addToStudy(w2, "Inside Wire")
56 id_w3 = geompy.addToStudy(w3, "Inside Wire, translated along OZ")
58 f12 = geompy.MakeFaces([w1, w2], 0)
59 id_f12 = geompy.addToStudy(f12, "MakeFaces WO + WI")
62 Box = geompy.MakeBoxDXDYDZ(200, 200, 200)
63 Orientation = geompy.OrientationChange(Box)
64 id_Orientation = geompy.addToStudy(Orientation, "OrientationChange")
66 # MakeCommon, MakeCut, MakeFuse, MakeSection
67 Sphere = geompy.MakeSphereR(100)
69 Common = geompy.MakeCommon (Box, Sphere)
70 Cut = geompy.MakeCut (Box, Sphere)
71 Fuse = geompy.MakeFuse (Box, Sphere)
72 Section = geompy.MakeSection(Box, Sphere)
74 id_Common = geompy.addToStudy(Common, "Common")
75 id_Cut = geompy.addToStudy(Cut, "Cut")
76 id_Fuse = geompy.addToStudy(Fuse, "Fuse")
77 id_Section = geompy.addToStudy(Section, "Section")
80 p100 = geompy.MakeVertex(100, 100, 100)
81 p300 = geompy.MakeVertex(300, 300, 300)
82 Box1 = geompy.MakeBoxTwoPnt(p100, p300)
83 Partition = geompy.Partition([Box], [Box1], [], [Box])
84 id_Partition = geompy.addToStudy(Partition, "Partition of Box by Box1")
86 # MakeMultiRotation1D, MakeMultiRotation2D
87 pz = geompy.MakeVertex(0, 0, 100)
88 vy = geompy.MakeVectorDXDYDZ(0, 100, 0)
90 MultiRot1D = geompy.MakeMultiRotation1D(f12, vy, pz, 6)
91 MultiRot2D = geompy.MakeMultiRotation2D(f12, vy, pz, 45, 6, 30, 3)
93 id_MultiRot1D = geompy.addToStudy(MultiRot1D, "MakeMultiRotation1D")
94 id_MultiRot2D = geompy.addToStudy(MultiRot2D, "MakeMultiRotation2D")
98 face5 = geompy.SubShapeSorted(Box, geompy.ShapeType["FACE"], [5])
99 f_glob_id = geompy.GetSubShapeID(Box, face5)
100 SuppFace = geompy.SuppressFaces(Box, [f_glob_id])
102 MakeFilletAll = geompy.MakeFilletAll(SuppFace, radius_fillet)
103 id_MakeFilletAll = geompy.addToStudy(MakeFilletAll, "MakeFilletAll")
106 dimension_chamfer = 10.
107 MakeChamferAll = geompy.MakeChamferAll(SuppFace, dimension_chamfer)
108 id_MakeChamferAll = geompy.addToStudy(MakeChamferAll, "MakeChamferAll")
113 box_faces = geompy.SubShapeAllSorted(Box, geompy.ShapeType["FACE"])
114 f_ind_1 = geompy.GetSubShapeID(Box, box_faces[0])
115 f_ind_2 = geompy.GetSubShapeID(Box, box_faces[1])
116 f_ind_3 = geompy.GetSubShapeID(Box, box_faces[2])
118 MakeChamfer = geompy.MakeChamfer(Box, d1, d2, geompy.ShapeType["FACE"],
119 [f_ind_1, f_ind_2, f_ind_3])
120 id_MakeChamfer = geompy.addToStudy(MakeChamfer, "MakeChamfer")
123 geompy.Export(f12, "/tmp/testExportImport.brep", "BREP")
125 # ExportBREP, ExportIGES, ExportSTEP
126 geompy.ExportBREP(f12, "/tmp/testExportImportBREP.brep")
127 geompy.ExportIGES(f12, "/tmp/testExportImportIGES.iges")
128 geompy.ExportSTEP(f12, "/tmp/testExportImportSTEP.step")
131 Import = geompy.Import("/tmp/testExportImport.brep", "BREP")
133 id_Import = geompy.addToStudy(Import, "Import")
135 # ImportBREP, ImportIGES, ImportSTEP
136 ImportBREP = geompy.ImportBREP("/tmp/testExportImportBREP.brep")
137 ImportIGES = geompy.ImportIGES("/tmp/testExportImportIGES.iges")
138 ImportSTEP = geompy.ImportSTEP("/tmp/testExportImportSTEP.step")
140 id_ImportBREP = geompy.addToStudy(ImportBREP, "ImportBREP")
141 id_ImportIGES = geompy.addToStudy(ImportIGES, "ImportIGES")
142 id_ImportSTEP = geompy.addToStudy(ImportSTEP, "ImportSTEP")
145 Compound = geompy.MakeCompound([Box, Sphere])
146 MakeBlockExplode = geompy.MakeBlockExplode(Compound, 6, 6)
148 id_MakeBlockExplode = geompy.addToStudy(MakeBlockExplode[0], "MakeBlockExplode")
150 # CheckCompoundOfBlocks
151 p1 = geompy.MakeVertex(200, 0, 0)
152 p2 = geompy.MakeVertex(400, 200, 200)
153 p3 = geompy.MakeVertex(400, 50, 50)
154 p4 = geompy.MakeVertex(600, 250, 250)
156 Box2 = geompy.MakeBoxTwoPnt(p1, p2)
157 Box3 = geompy.MakeBoxTwoPnt(p3, p4)
158 Cyl = geompy.MakeCylinderRH(50, 300)
159 Cone = geompy.MakeConeR1R2H(150, 10, 400)
161 Compound1 = geompy.MakeCompound([Box, Cyl, Cone, Box3, Box2])
163 IsValid = geompy.CheckCompoundOfBlocks(Compound1)
165 print "The Blocks Compound is NOT VALID"
167 print "The Blocks Compound is VALID"
169 IsValid = geompy.CheckCompoundOfBlocks(Box)
171 print "The Box is NOT VALID"
173 print "The Box is VALID"
175 # test geometrical groups
178 CreateGroup = geompy.CreateGroup(Box, geompy.ShapeType["FACE"])
180 id_CreateGroup = geompy.addToStudy(CreateGroup, "CreateGroup")
183 f_ind_4 = geompy.GetSubShapeID(Box, box_faces[3])
184 f_ind_5 = geompy.GetSubShapeID(Box, box_faces[4])
185 f_ind_6 = geompy.GetSubShapeID(Box, box_faces[5])
187 geompy.AddObject(CreateGroup, f_ind_6)
188 geompy.AddObject(CreateGroup, f_ind_1)
189 geompy.AddObject(CreateGroup, f_ind_4)
191 # RemoveObject(theGroup, theSubShapeID)
192 geompy.RemoveObject(CreateGroup, f_ind_1)
195 GetObjectIDs = geompy.GetObjectIDs(CreateGroup)
197 print "Group of Box's faces includes the following IDs:"
198 for ObjectID in GetObjectIDs: