Back to index

salome-geom  6.5.0
GEOM_TestOthers.py
Go to the documentation of this file.
00001 #  -*- coding: iso-8859-1 -*-
00002 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00003 #
00004 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00005 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00006 #
00007 # This library is free software; you can redistribute it and/or
00008 # modify it under the terms of the GNU Lesser General Public
00009 # License as published by the Free Software Foundation; either
00010 # version 2.1 of the License.
00011 #
00012 # This library is distributed in the hope that it will be useful,
00013 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 # Lesser General Public License for more details.
00016 #
00017 # You should have received a copy of the GNU Lesser General Public
00018 # License along with this library; if not, write to the Free Software
00019 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00020 #
00021 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00022 #
00023 #  File   : GEOM_TestOthers.py
00024 #  Author : Julia DOROVSKIKH
00025 #  Module : GEOM
00026 #  $Header: /home/server/cvs/GEOM/GEOM_SRC/src/GEOM_SWIG/GEOM_TestOthers.py,v 1.16.2.7.4.6.14.2 2012-05-03 12:23:00 ouv Exp $
00027 #
00028 # ! Please, if you edit this example file, update also
00029 # ! GEOM_SRC/doc/salome/gui/GEOM/input/tui_test_others.doc
00030 # ! as some sequences of symbols from this example are used during
00031 # ! documentation generation to identify certain places of this file
00032 
00033 import os
00034 
00035 def TestExportImport (geompy, shape):
00036 
00037   print "Test Export/Import ...",
00038 
00039   tmpDir = os.getenv("TEMP")
00040   if tmpDir == None:
00041     tmpDir = "/tmp"
00042 
00043   # Files for Export/Import testing
00044   fileExportImport = tmpDir + "/testExportImport.brep"
00045   fileExportImportBREP = tmpDir + "/testExportImportBREP.brep"
00046   fileExportImportIGES = tmpDir + "/testExportImportIGES.iges"
00047   fileExportImportSTEP = tmpDir + "/testExportImportSTEP.step"
00048 
00049   if os.access(fileExportImport, os.F_OK):
00050     if os.access(fileExportImport, os.W_OK):
00051       os.remove(fileExportImport)
00052     else:
00053       fileExportImport = tmpDir + "/testExportImport1.brep"
00054 
00055     if os.access(fileExportImportBREP, os.W_OK):
00056       os.remove(fileExportImportBREP)
00057     else:
00058       fileExportImportBREP = tmpDir + "/testExportImportBREP1.brep"
00059 
00060     if os.access(fileExportImportIGES, os.W_OK):
00061       os.remove(fileExportImportIGES)
00062     else:
00063       fileExportImportIGES = tmpDir + "/testExportImportIGES1.iges"
00064 
00065     if os.access(fileExportImportSTEP, os.W_OK):
00066       os.remove(fileExportImportSTEP)
00067     else:
00068       fileExportImportSTEP = tmpDir + "/testExportImportSTEP1.step"
00069 
00070   # Export
00071   geompy.Export(shape, fileExportImport, "BREP")
00072 
00073   # ExportBREP, ExportIGES, ExportSTEP
00074   geompy.ExportBREP(shape, fileExportImportBREP)
00075   geompy.ExportIGES(shape, fileExportImportIGES)
00076   geompy.ExportSTEP(shape, fileExportImportSTEP)
00077 
00078   # Import
00079   Import = geompy.ImportFile(fileExportImport, "BREP")
00080 
00081   id_Import = geompy.addToStudy(Import, "Import")
00082 
00083   # ImportBREP, ImportIGES, ImportSTEP
00084   ImportBREP = geompy.ImportBREP(fileExportImportBREP)
00085   ImportIGES = geompy.ImportIGES(fileExportImportIGES)
00086   ImportSTEP = geompy.ImportSTEP(fileExportImportSTEP)
00087 
00088   id_ImportBREP = geompy.addToStudy(ImportBREP, "ImportBREP")
00089   id_ImportIGES = geompy.addToStudy(ImportIGES, "ImportIGES")
00090   id_ImportSTEP = geompy.addToStudy(ImportSTEP, "ImportSTEP")
00091 
00092   # Remove files for Export/Import testing
00093   os.remove(fileExportImport)
00094   os.remove(fileExportImportBREP)
00095   os.remove(fileExportImportIGES)
00096   os.remove(fileExportImportSTEP)
00097 
00098   print "OK"
00099 
00100 
00101 def TestOtherOperations (geompy, math):
00102 
00103   # prepare data for further operations
00104   vx = geompy.MakeVectorDXDYDZ( 1,  0,  0)
00105   vy = geompy.MakeVectorDXDYDZ( 0,  1,  0)
00106   vz = geompy.MakeVectorDXDYDZ( 0,  0,  1)
00107 
00108   v_y = geompy.MakeVectorDXDYDZ( 0, -1,  0)
00109 
00110   p11 = geompy.MakeVertex( 0,  0, 0)
00111   p12 = geompy.MakeVertex(30,  0, 0)
00112   p13 = geompy.MakeVertex(30, 30, 0)
00113   p14 = geompy.MakeVertex( 0, 30, 0)
00114 
00115   p21 = geompy.MakeVertex(10, 10, 0)
00116   p22 = geompy.MakeVertex(20, 10, 0)
00117   p23 = geompy.MakeVertex(20, 20, 0)
00118   p24 = geompy.MakeVertex(10, 20, 0)
00119 
00120   e11 = geompy.MakeEdge(p11, p12)
00121   e12 = geompy.MakeEdge(p12, p13)
00122   e13 = geompy.MakeEdge(p13, p14)
00123   e14 = geompy.MakeEdge(p14, p11)
00124 
00125   e21 = geompy.MakeEdge(p21, p22)
00126   e22 = geompy.MakeEdge(p22, p23)
00127   e23 = geompy.MakeEdge(p23, p24)
00128   e24 = geompy.MakeEdge(p24, p21)
00129 
00130   w1 = geompy.MakeWire([e11, e12, e13, e14])
00131   w2 = geompy.MakeWire([e21, e22, e23, e24])
00132   w3 = geompy.MakeTranslation(w2, 0, 0, 10)
00133 
00134   id_w1 = geompy.addToStudy(w1, "Outside Wire")
00135   id_w2 = geompy.addToStudy(w2, "Inside Wire")
00136   id_w3 = geompy.addToStudy(w3, "Inside Wire, translated along OZ")
00137 
00138   # MakeFaces
00139   f12 = geompy.MakeFaces([w1, w2], 0)
00140   id_f12 = geompy.addToStudy(f12, "MakeFaces WO + WI")
00141 
00142   # Export/Import
00143   TestExportImport(geompy, f12)
00144 
00145   # OrientationChange
00146   Box = geompy.MakeBoxDXDYDZ(200, 200, 200)
00147   Orientation = geompy.OrientationChange(Box)
00148   id_Orientation = geompy.addToStudy(Orientation, "OrientationChange")
00149 
00150   # MakeCommon, MakeCut, MakeFuse, MakeSection
00151   Sphere = geompy.MakeSphereR(100)
00152 
00153   Common  = geompy.MakeCommon (Box, Sphere)
00154   Cut     = geompy.MakeCut    (Box, Sphere)
00155   Fuse    = geompy.MakeFuse   (Box, Sphere)
00156   Section = geompy.MakeSection(Box, Sphere)
00157 
00158   id_Common  = geompy.addToStudy(Common,  "Common")
00159   id_Cut     = geompy.addToStudy(Cut,     "Cut")
00160   id_Fuse    = geompy.addToStudy(Fuse,    "Fuse")
00161   id_Section = geompy.addToStudy(Section, "Section")
00162 
00163   # Partition
00164   p100 = geompy.MakeVertex(100, 100, 100)
00165   p300 = geompy.MakeVertex(300, 300, 300)
00166   Box1 = geompy.MakeBoxTwoPnt(p100, p300)
00167   #Partition = geompy.Partition([Box], [Box1], [], [Box])
00168   Partition = geompy.Partition([Box], [Box1])
00169   id_Partition = geompy.addToStudy(Partition, "Partition of Box by Box1")
00170 
00171   # MakeMultiRotation1D, MakeMultiRotation2D
00172   pz = geompy.MakeVertex(0, 0, 100)
00173   vy = geompy.MakeVectorDXDYDZ(0, 100, 0)
00174 
00175   MultiRot1D = geompy.MakeMultiRotation1D(f12, vy, pz, 6)
00176   MultiRot2D = geompy.MakeMultiRotation2D(f12, vy, pz, 45, 6, 30, 3)
00177 
00178   id_MultiRot1D = geompy.addToStudy(MultiRot1D, "MakeMultiRotation1D")
00179   id_MultiRot2D = geompy.addToStudy(MultiRot2D, "MakeMultiRotation2D")
00180 
00181   # MakeFilletAll
00182   radius_fillet = 10.
00183   face5 = geompy.SubShapeSortedCentres(Box, geompy.ShapeType["FACE"], [5])
00184   f_glob_id = geompy.GetSubShapeID(Box, face5)
00185   SuppFace = geompy.SuppressFaces(Box, [f_glob_id])
00186 
00187   MakeFilletAll = geompy.MakeFilletAll(SuppFace, radius_fillet)
00188   id_MakeFilletAll = geompy.addToStudy(MakeFilletAll, "MakeFilletAll")
00189 
00190   # MakeChamferAll
00191   dimension_chamfer = 10.
00192   MakeChamferAll = geompy.MakeChamferAll(SuppFace, dimension_chamfer)
00193   id_MakeChamferAll = geompy.addToStudy(MakeChamferAll, "MakeChamferAll")
00194 
00195   # MakeChamfer
00196   d1 = 13.
00197   d2 = 7.
00198   box_faces = geompy.SubShapeAllSortedCentres(Box, geompy.ShapeType["FACE"])
00199   f_ind_1 = geompy.GetSubShapeID(Box, box_faces[0])
00200   f_ind_2 = geompy.GetSubShapeID(Box, box_faces[1])
00201   f_ind_3 = geompy.GetSubShapeID(Box, box_faces[2])
00202 
00203   MakeChamfer = geompy.MakeChamfer(Box, d1, d2, geompy.ShapeType["FACE"],
00204                                    [f_ind_1, f_ind_2, f_ind_3])
00205   id_MakeChamfer = geompy.addToStudy(MakeChamfer, "MakeChamfer")
00206 
00207   # NumberOf
00208   NumberOfFaces = geompy.NumberOfFaces(Box)
00209   if NumberOfFaces != 6:
00210     print "Bad number of faces in BOX!"
00211 
00212   NumberOfEdges = geompy.NumberOfEdges(Box)
00213   if NumberOfEdges != 12:
00214     print "Bad number of edges in BOX!"
00215 
00216   NumberOfSolids = geompy.NumberOfSolids(Box)
00217   if NumberOfSolids != 1:
00218     print "Bad number of solids in BOX!"
00219 
00220   NumberOfShapes = geompy.NumberOfSubShapes(Box, geompy.ShapeType["SHAPE"])
00221   if NumberOfShapes != 34:
00222     print "Bad number of shapes in BOX!"
00223 
00224   # MakeBlockExplode
00225   Compound = geompy.MakeCompound([Box, Sphere])
00226   MakeBlockExplode = geompy.MakeBlockExplode(Compound, 6, 6)
00227 
00228   id_MakeBlockExplode = geompy.addToStudy(MakeBlockExplode[0], "MakeBlockExplode")
00229 
00230   # CheckCompoundOfBlocks
00231   p1 = geompy.MakeVertex(200, 0, 0)
00232   p2 = geompy.MakeVertex(400, 200, 200)
00233   p3 = geompy.MakeVertex(400, 50, 50)
00234   p4 = geompy.MakeVertex(600, 250, 250)
00235 
00236   Box2 = geompy.MakeBoxTwoPnt(p1, p2)
00237   Box3 = geompy.MakeBoxTwoPnt(p3, p4)
00238   Cyl  = geompy.MakeCylinderRH(50, 300)
00239   Cone = geompy.MakeConeR1R2H(150, 10, 400)
00240 
00241   Compound1 = geompy.MakeCompound([Box, Cyl, Cone, Box3, Box2])
00242 
00243   IsValid = geompy.CheckCompoundOfBlocks(Compound1)
00244   if IsValid == 0:
00245     print "The Blocks Compound is NOT VALID"
00246   else:
00247     print "The Blocks Compound is VALID"
00248 
00249   IsValid = geompy.CheckCompoundOfBlocks(Box)
00250   if IsValid == 0:
00251     print "The Box is NOT VALID"
00252   else:
00253     print "The Box is VALID"
00254 
00255   # GetSame
00256   Cone_ss = geompy.GetSame(Compound1, Cone)
00257   id_Cone_ss = geompy.addToStudyInFather(Compound1, Cone_ss, "Cone subshape")
00258 
00259   # test geometrical groups
00260 
00261   # CreateGroup
00262   CreateGroup = geompy.CreateGroup(Box, geompy.ShapeType["FACE"])
00263 
00264   id_CreateGroup = geompy.addToStudy(CreateGroup, "CreateGroup")
00265 
00266   # AddObject
00267   f_ind_4 = geompy.GetSubShapeID(Box, box_faces[3])
00268   f_ind_5 = geompy.GetSubShapeID(Box, box_faces[4])
00269   f_ind_6 = geompy.GetSubShapeID(Box, box_faces[5])
00270 
00271   geompy.AddObject(CreateGroup, f_ind_6) # box_faces[5]
00272   geompy.AddObject(CreateGroup, f_ind_1) # box_faces[0]
00273   geompy.AddObject(CreateGroup, f_ind_4) # box_faces[3]
00274   # Now contains f_ind_6, f_ind_1, f_ind_4
00275 
00276   # UnionList
00277   geompy.UnionList(CreateGroup, [box_faces[2], box_faces[4], box_faces[5]])
00278   # Now contains f_ind_6, f_ind_1, f_ind_4, f_ind_3, f_ind_5
00279 
00280   # RemoveObject(theGroup, theSubShapeID)
00281   geompy.RemoveObject(CreateGroup, f_ind_1) # box_faces[0]
00282   # Now contains f_ind_6, f_ind_4, f_ind_3, f_ind_5
00283 
00284   # DifferenceList
00285   geompy.DifferenceList(CreateGroup, [box_faces[1], box_faces[0], box_faces[3]])
00286   # Now contains f_ind_6, f_ind_3, f_ind_5
00287 
00288   # GetObjectIDs
00289   GetObjectIDs = geompy.GetObjectIDs(CreateGroup)
00290 
00291   print "Group of Box's faces includes the following IDs:"
00292   print "(must be ", f_ind_6, ", ", f_ind_3, " and ", f_ind_5, ")"
00293   for ObjectID in GetObjectIDs:
00294     print " ", ObjectID
00295 
00296   # GetMainShape
00297   BoxCopy = geompy.GetMainShape(CreateGroup)
00298 
00299   # DifferenceIDs
00300   geompy.DifferenceIDs(CreateGroup, [f_ind_3, f_ind_5])
00301   # Now contains f_ind_6
00302 
00303   # UnionIDs
00304   geompy.UnionIDs(CreateGroup, [f_ind_1, f_ind_2, f_ind_6])
00305   # Now contains f_ind_6, f_ind_1, f_ind_2
00306 
00307   # Check
00308   GetObjectIDs = geompy.GetObjectIDs(CreateGroup)
00309   print "Group of Box's faces includes the following IDs:"
00310   print "(must be ", f_ind_6, ", ", f_ind_1, " and ", f_ind_2, ")"
00311   for ObjectID in GetObjectIDs:
00312     print " ", ObjectID
00313 
00314   # -----------------------------------------------------------------------------
00315   # enumeration ShapeTypeString as a dictionary
00316   # -----------------------------------------------------------------------------
00317   ShapeTypeString = {'0':"COMPOUND", '1':"COMPSOLID", '2':"SOLID", '3':"SHELL",
00318                      '4':"FACE", '5':"WIRE", '6':"EDGE", '7':"VERTEX", '8':"SHAPE"}
00319 
00320   GroupType = geompy.GetType(CreateGroup)
00321   print "Type of elements of the created group is ", ShapeTypeString[`GroupType`]
00322 
00323   # Prepare data for the following operations
00324   p0 = geompy.MakeVertex(0, 0, 0)
00325   b0 = geompy.MakeBox(-50, -50, -50, 50, 50, 50)
00326   s0 = geompy.MakeSphereR(100)
00327 
00328   id_b0 = geompy.addToStudy(b0, "b0")
00329   id_s0 = geompy.addToStudy(s0, "s0")
00330 
00331   v_0pp = geompy.MakeVectorDXDYDZ( 0,  1,  1)
00332   #v_0np = geompy.MakeVectorDXDYDZ( 0, -1,  1)
00333   v_p0p = geompy.MakeVectorDXDYDZ( 1,  0,  1)
00334   v_p0n = geompy.MakeVectorDXDYDZ(1,  0,  -1)
00335   v_pp0 = geompy.MakeVectorDXDYDZ( 1,  1,  0)
00336   v_pn0 = geompy.MakeVectorDXDYDZ(1,  -1,  0)
00337 
00338   #pln_0pp = geompy.MakePlane(p0, v_0pp, 300)
00339   #pln_0np = geompy.MakePlane(p0, v_0np, 300)
00340   pln_p0p = geompy.MakePlane(p0, v_p0p, 300)
00341   pln_p0n = geompy.MakePlane(p0, v_p0n, 300)
00342   pln_pp0 = geompy.MakePlane(p0, v_pp0, 300)
00343   pln_pn0 = geompy.MakePlane(p0, v_pn0, 300)
00344   #
00345   #part_objs = [b0, pln_0pp, pln_0np, pln_p0p, pln_n0p, pln_pp0, pln_np0]
00346   #part_tool_1 = geompy.MakePartition(part_objs, [], [], [b0])
00347   #part_tool_1 = geompy.MakePartition(part_objs)
00348   #
00349   #id_part_tool_1 = geompy.addToStudy(part_tool_1, "part_tool_1")
00350   #
00351   #pt_pnt_1  = geompy.MakeVertex( 55,   0,  55)
00352   #pt_pnt_2  = geompy.MakeVertex(  0,  55,  55)
00353   #pt_pnt_3  = geompy.MakeVertex(-55,   0,  55)
00354   #pt_pnt_4  = geompy.MakeVertex(  0, -55,  55)
00355   #pt_pnt_5  = geompy.MakeVertex( 55,  55,   0)
00356   #pt_pnt_6  = geompy.MakeVertex( 55, -55,   0)
00357   #pt_pnt_7  = geompy.MakeVertex(-55,  55,   0)
00358   #pt_pnt_8  = geompy.MakeVertex(-55, -55,   0)
00359   #pt_pnt_9  = geompy.MakeVertex( 55,   0, -55)
00360   #pt_pnt_10 = geompy.MakeVertex(  0,  55, -55)
00361   #pt_pnt_11 = geompy.MakeVertex(-55,   0, -55)
00362   #pt_pnt_12 = geompy.MakeVertex(  0, -55, -55)
00363   #
00364   #pt_face_1  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_1)
00365   #pt_face_2  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_2)
00366   #pt_face_3  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_3)
00367   #pt_face_4  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_4)
00368   #pt_face_5  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_5)
00369   #pt_face_6  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_6)
00370   #pt_face_7  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_7)
00371   #pt_face_8  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_8)
00372   #pt_face_9  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_9)
00373   #pt_face_10 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_10)
00374   #pt_face_11 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_11)
00375   #pt_face_12 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_12)
00376   #
00377   #pt_box = geompy.GetBlockNearPoint(part_tool_1, p0)
00378   #
00379   #comp_parts = [pt_face_1, pt_face_4, pt_face_7, pt_face_10,
00380   #              pt_face_2, pt_face_5, pt_face_8, pt_face_11,
00381   #              #pt_face_3, pt_face_6, pt_face_9, pt_face_12, pt_box]
00382   #              pt_face_3, pt_face_6, pt_face_9, pt_face_12]
00383   #part_tool = geompy.MakeCompound(comp_parts)
00384   #id_part_tool = geompy.addToStudy(part_tool, "part_tool")
00385   #
00386   #part = geompy.MakePartition([s0], [part_tool])
00387   #
00388   #part_tools = [pt_face_1, pt_face_4, pt_face_7, pt_face_10,
00389   #              pt_face_2, pt_face_5, pt_face_8, pt_face_11,
00390   #              pt_face_3, pt_face_6, pt_face_9, pt_face_12, b0]
00391   #part = geompy.MakePartition([s0], part_tools)
00392 
00393   p1 = geompy.MakeVertex(50, 0, 0)
00394   p2 = geompy.MakeVertex(-50, 0, 0)
00395   p3 = geompy.MakeVertex(0, 50, 0)
00396   p4 = geompy.MakeVertex(0, -50, 0)
00397   p5 = geompy.MakeVertex(0, 0, 50)
00398   p6 = geompy.MakeVertex(0, 0, -50)
00399 
00400   plnX1 = geompy.MakePlane(p1, vx, 300)
00401   plnX2 = geompy.MakePlane(p2, vx, 300)
00402   plnY1 = geompy.MakePlane(p3, vy, 300)
00403   plnY2 = geompy.MakePlane(p4, vy, 300)
00404   plnZ1 = geompy.MakePlane(p5, vz, 300)
00405   plnZ2 = geompy.MakePlane(p6, vz, 300)
00406 
00407   #part = geompy.MakePartition([s0], [plnX1,plnX2,plnY1,plnY2,plnZ1,plnZ2])
00408   part = geompy.MakePartition([s0], [plnX1])
00409   part = geompy.MakePartition([part], [plnX2])
00410   part = geompy.MakePartition([part], [plnY1])
00411   part = geompy.MakePartition([part], [plnY2])
00412   part = geompy.MakePartition([part], [plnZ1])
00413   part = geompy.MakePartition([part], [plnZ2])
00414   geompy.addToStudy(part, "part")
00415 
00416   # GetFreeFacesIDs
00417   anIDs = geompy.GetFreeFacesIDs(part)
00418   freeFaces = geompy.GetSubShape(part, anIDs)
00419 
00420   geompy.addToStudy(freeFaces, "freeFaces")
00421 
00422   # RemoveExtraEdges with union of all faces, sharing common surfaces
00423   tools = [pln_pp0, pln_pn0, pln_p0p, pln_p0n]
00424 
00425   Partition_1 = geompy.MakePartition([Sphere], tools, [], [], geompy.ShapeType["SOLID"], 0, [])
00426   geompy.addToStudy(Partition_1, "Partition_1")
00427 
00428   faces = geompy.SubShapeAllSortedCentres(Partition_1, geompy.ShapeType["FACE"])
00429 
00430   Face_1 = faces[0]
00431   Face_2 = faces[39]
00432   Face_3 = faces[40]
00433 
00434   geompy.addToStudyInFather(Partition_1, Face_1, "Face_1")
00435   geompy.addToStudyInFather(Partition_1, Face_2, "Face_2")
00436   geompy.addToStudyInFather(Partition_1, Face_3, "Face_3")
00437 
00438   Vector_5 = geompy.MakeVectorDXDYDZ(0, 20, 0)
00439   geompy.addToStudy(Vector_5, "Vector_5")
00440 
00441   Rotation_1 = geompy.MakeRotation(Face_1, Vector_5, 90*math.pi/180.0)
00442   Rotation_2 = geompy.MakeRotation(Face_1, Vector_5, 180*math.pi/180.0)
00443   Rotation_3 = geompy.MakeRotation(Face_1, Vector_5, 270*math.pi/180.0)
00444 
00445   geompy.addToStudy(Rotation_1, "Rotation_1")
00446   geompy.addToStudy(Rotation_2, "Rotation_2")
00447   geompy.addToStudy(Rotation_3, "Rotation_3")
00448 
00449   Vector_6 = geompy.MakeVectorDXDYDZ(0, 0, 20)
00450   geompy.addToStudy(Vector_6, "Vector_6")
00451 
00452   Rotation_4 = geompy.MakeRotation(Face_1, Vector_6, 90*math.pi/180.0)
00453   Rotation_5 = geompy.MakeRotation(Face_1, Vector_6, -90*math.pi/180.0)
00454   geompy.addToStudy(Rotation_4, "Rotation_4")
00455   geompy.addToStudy(Rotation_5, "Rotation_5")
00456 
00457   Shell_1 = geompy.MakeShell([Face_1, Rotation_1, Rotation_2, Rotation_3, Rotation_4, Rotation_5])
00458   Solid_1 = geompy.MakeSolid([Shell_1])
00459   NoExtraEdges_1 = geompy.RemoveExtraEdges(Solid_1, True) # doUnionFaces = True
00460 
00461   geompy.addToStudy(Shell_1, "Shell_1")
00462   geompy.addToStudy(Solid_1, "Solid_1")
00463   geompy.addToStudy(NoExtraEdges_1, "NoExtraEdges_1")
00464 
00465   # RemoveExtraEdges (by default, doUnionFaces = False)
00466   freeFacesWithoutExtra = geompy.RemoveExtraEdges(freeFaces)
00467 
00468   geompy.addToStudy(freeFacesWithoutExtra, "freeFacesWithoutExtra")
00469 
00470   # GetSharedShapes
00471   sharedFaces = geompy.GetSharedShapes(part, freeFaces,
00472                                        geompy.ShapeType["FACE"])
00473   ind = 1
00474   for shFace in sharedFaces:
00475     geompy.addToStudy(shFace, "sharedFace_" + `ind`)
00476     ind = ind + 1
00477     pass
00478 
00479   sharedEdges = geompy.GetSharedShapesMulti([part, freeFaces],
00480                                              geompy.ShapeType["EDGE"])
00481   ind = 1
00482   for shEdge in sharedEdges:
00483     geompy.addToStudy(shEdge, "sharedEdge_" + `ind`)
00484     ind = ind + 1
00485     pass
00486 
00487   # CheckAndImprove
00488   blocksComp = geompy.CheckAndImprove(part)
00489 
00490   geompy.addToStudy(blocksComp, "blocksComp")
00491 
00492   # Propagate
00493   listChains = geompy.Propagate(blocksComp)
00494 
00495   for chain in listChains:
00496     geompy.addToStudyInFather(blocksComp, chain, "propagation chain")
00497 
00498   # GetPoint(theShape, theX, theY, theZ, theEpsilon)
00499   #
00500   # (-50,  50, 50) .-----. (50,  50, 50)
00501   #      pb0_top_1 |     |
00502   #                |     . pmidle
00503   #                |     |
00504   # (-50, -50, 50) '-----' (50, -50, 50)
00505   #
00506   pb0_top_1 = geompy.GetPoint(blocksComp, -50,  50,  50, 0.01)
00507   pb0_bot_1 = geompy.GetPoint(blocksComp, -50, -50, -50, 0.01)
00508 
00509   geompy.addToStudyInFather(blocksComp, pb0_top_1, "point from blocksComp (-50,  50,  50)")
00510   geompy.addToStudyInFather(blocksComp, pb0_bot_1, "point from blocksComp (-50, -50, -50)")
00511 
00512   # GetVertexNearPoint(theShape, thePoint)
00513   pb0_top_2_near = geompy.MakeVertex(40, 40, 40)
00514   pb0_top_2      = geompy.GetVertexNearPoint(blocksComp, pb0_top_2_near)
00515 
00516   geompy.addToStudyInFather(blocksComp, pb0_top_2, "point from blocksComp near (40,  40,  40)")
00517 
00518   # GetEdge(theShape, thePoint1, thePoint2)
00519   edge_top_y50 = geompy.GetEdge(blocksComp, pb0_top_1, pb0_top_2)
00520 
00521   geompy.addToStudyInFather(blocksComp, edge_top_y50, "edge from blocksComp by two points")
00522 
00523   # GetEdgeNearPoint(theShape, thePoint)
00524   pmidle = geompy.MakeVertex(50, 0, 50)
00525   edge1 = geompy.GetEdgeNearPoint(blocksComp, pmidle)
00526 
00527   geompy.addToStudyInFather(blocksComp, edge1, "edge near point (50, 0, 50)")
00528 
00529   # GetBlockByParts(theCompound, theParts)
00530   b0_image = geompy.GetBlockByParts(blocksComp, [pb0_top_1, pb0_bot_1, edge1])
00531 
00532   geompy.addToStudyInFather(blocksComp, b0_image, "b0 image")
00533 
00534   # GetShapesNearPoint(theShape, thePoint, theShapeType, theTolerance)
00535   b0_faces_plus = geompy.GetShapesNearPoint(blocksComp, pb0_top_2_near, geompy.ShapeType["FACE"], 0.01)
00536 
00537   geompy.addToStudyInFather(blocksComp, b0_faces_plus, "faces near point (40,  40,  40)")
00538 
00539   # GetShapesOnPlane
00540   faces_on_pln = geompy.GetShapesOnPlane(blocksComp, geompy.ShapeType["FACE"],
00541                                          v_0pp, geompy.GEOM.ST_ONIN)
00542   for face_i in faces_on_pln:
00543     geompy.addToStudy(face_i, "Face on Plane (N = (0, 1, 1)) or below it")
00544 
00545   # GetShapesOnPlaneIDs
00546   faces_above_pln_ids = geompy.GetShapesOnPlaneIDs(blocksComp, geompy.ShapeType["FACE"],
00547                                                    v_0pp, geompy.GEOM.ST_OUT)
00548   faces_above = geompy.CreateGroup(blocksComp, geompy.ShapeType["FACE"])
00549   geompy.UnionIDs(faces_above, faces_above_pln_ids)
00550   geompy.addToStudy(faces_above, "Group of faces above Plane (N = (0, 1, 1))")
00551 
00552   # GetShapesOnPlaneWithLocation
00553   Loc = geompy.MakeVertex(0, -50, 0)
00554   edges_on_pln = geompy.GetShapesOnPlaneWithLocation(blocksComp, geompy.ShapeType["EDGE"],
00555                                                      v_y, Loc, geompy.GEOM.ST_ON)
00556   for edge_i in edges_on_pln:
00557     geompy.addToStudy(edge_i, "Edge on Plane (N = (0, -1, 0) & Location = (0, -50, 0)")
00558 
00559   # GetShapesOnPlaneWithLocationIDs
00560   edges_on_pln_ids = geompy.GetShapesOnPlaneWithLocationIDs(
00561            blocksComp, geompy.ShapeType["EDGE"], v_y, Loc, geompy.GEOM.ST_ON)
00562   group_edges_on_pln = geompy.CreateGroup(blocksComp, geompy.ShapeType["EDGE"])
00563   geompy.UnionIDs(group_edges_on_pln, edges_on_pln_ids)
00564   grname = "Group of edges on Plane (N = (0, -1, 0) & Location = (0, -50, 0))"
00565   geompy.addToStudy(group_edges_on_pln, grname)
00566 
00567   # GetShapesOnCylinder
00568   edges_out_cyl = geompy.GetShapesOnCylinder(blocksComp, geompy.ShapeType["EDGE"],
00569                                              vy, 55, geompy.GEOM.ST_OUT)
00570   for edge_i in edges_out_cyl:
00571     geompy.addToStudy(edge_i, "Edge out of Cylinder (axis = (0, 1, 0), r = 55)")
00572 
00573   # GetShapesOnCylinderIDs
00574   edges_in_cyl_ids = geompy.GetShapesOnCylinderIDs(blocksComp, geompy.ShapeType["EDGE"],
00575                                                    vy, 80, geompy.GEOM.ST_IN)
00576   edges_in = geompy.CreateGroup(blocksComp, geompy.ShapeType["EDGE"])
00577   geompy.UnionIDs(edges_in, edges_in_cyl_ids)
00578   geompy.addToStudy(edges_in, "Group of edges inside Cylinder (axis = (0, 1, 0), r = 55)")
00579 
00580   # GetShapesOnCylinderWithLocation
00581   edges_out_cyl = geompy.GetShapesOnCylinderWithLocation(blocksComp, geompy.ShapeType["EDGE"],
00582                                                          vy, p11, 55, geompy.GEOM.ST_OUT)
00583   for edge_i in edges_out_cyl:
00584     geompy.addToStudy(edge_i, "Edge out of Cylinder (axis = (0, 1, 0),  loc = (0, 0, 0), r = 55)")
00585 
00586   # GetShapesOnCylinderWithLocationIDs
00587   edges_in_cyl_ids = geompy.GetShapesOnCylinderWithLocationIDs(blocksComp, geompy.ShapeType["EDGE"],
00588                                                                vy, p11, 80, geompy.GEOM.ST_IN)
00589   edges_in = geompy.CreateGroup(blocksComp, geompy.ShapeType["EDGE"])
00590   geompy.UnionIDs(edges_in, edges_in_cyl_ids)
00591   geompy.addToStudy(edges_in, "Group of edges inside Cylinder (axis = (0, 1, 0), loc = (0, 0, 0), r = 80)")
00592 
00593   # GetShapesOnSphere
00594   vertices_on_sph = geompy.GetShapesOnSphere(blocksComp, geompy.ShapeType["VERTEX"],
00595                                              p0, 100, geompy.GEOM.ST_ON)
00596   for vertex_i in vertices_on_sph:
00597     geompy.addToStudy(vertex_i, "Vertex on Sphere (center = (0, 0, 0), r = 100)")
00598 
00599   # GetShapesOnSphereIDs
00600   vertices_on_sph_ids = geompy.GetShapesOnSphereIDs(blocksComp, geompy.ShapeType["VERTEX"],
00601                                                     p0, 100, geompy.GEOM.ST_ON)
00602   vertices_on = geompy.CreateGroup(blocksComp, geompy.ShapeType["VERTEX"])
00603   geompy.UnionIDs(vertices_on, vertices_on_sph_ids)
00604   geompy.addToStudy(vertices_on, "Group of vertices on Sphere (center = (0, 0, 0), r = 100)")
00605 
00606   # GetShapesOnQuadrangle
00607 
00608   geompy.addToStudy(f12, "F12" )
00609 
00610   bl = geompy.MakeVertex(10,-10, 0)
00611   br = geompy.MakeVertex(40,-10, 0)
00612   tr = geompy.MakeVertex(40, 20, 0)
00613   tl = geompy.MakeVertex(10, 20, 0)
00614   qe1 = geompy.MakeEdge(bl, br)
00615   qe2 = geompy.MakeEdge(br, tr)
00616   qe3 = geompy.MakeEdge(tr, tl)
00617   qe4 = geompy.MakeEdge(tl, bl)
00618   quadrangle = geompy.MakeWire([qe1, qe2, qe3, qe4])
00619   geompy.addToStudy(quadrangle, "Quadrangle")
00620 
00621   edges_onin_quad = geompy.GetShapesOnQuadrangle(f12, geompy.ShapeType["EDGE"],
00622                                                  tl, tr, bl, br, geompy.GEOM.ST_ONIN)
00623   comp = geompy.MakeCompound(edges_onin_quad)
00624   geompy.addToStudy(comp, "Edges of F12 ONIN Quadrangle")
00625   if len( edges_onin_quad ) != 4:
00626     print "Error in GetShapesOnQuadrangle()"
00627 
00628   # GetShapesOnQuadrangleIDs
00629   vertices_on_quad_ids = geompy.GetShapesOnQuadrangleIDs(f12, geompy.ShapeType["VERTEX"],
00630                                                          tl, tr, bl, br, geompy.GEOM.ST_ON)
00631   vertices_on_quad = geompy.CreateGroup(f12, geompy.ShapeType["VERTEX"])
00632   geompy.UnionIDs(vertices_on_quad, vertices_on_quad_ids)
00633   geompy.addToStudy(vertices_on_quad, "Group of vertices on Quadrangle F12")
00634 
00635   # GetShapesOnBox
00636   edges_on_box = geompy.GetShapesOnBox(b0, part, geompy.ShapeType["EDGE"],
00637                                        geompy.GEOM.ST_ON)
00638   comp = geompy.MakeCompound(edges_on_box)
00639   geompy.addToStudy(comp, "Edges of part ON box b0")
00640   if len( edges_on_box ) != 12:
00641     print "Error in GetShapesOnBox()"
00642 
00643   # GetShapesOnBoxIDs
00644   faces_on_box_ids = geompy.GetShapesOnBoxIDs(b0, part, geompy.ShapeType["FACE"],
00645                                               geompy.GEOM.ST_ON)
00646   faces_on_box = geompy.CreateGroup(part, geompy.ShapeType["FACE"])
00647   geompy.UnionIDs(faces_on_box, faces_on_box_ids)
00648   geompy.addToStudyInFather(part, faces_on_box, "Group of faces on box b0")
00649 
00650   # Prepare arguments for GetShapesOnShape
00651   sph1 = geompy.MakeSphere(50, 50,  50, 40)
00652   sph2 = geompy.MakeSphere(50, 50, -50, 40)
00653   pcyl = geompy.MakeVertex(50, 50, -50)
00654   cyli = geompy.MakeCylinder(pcyl, vz, 40, 100)
00655   fuse = geompy.MakeFuse(sph1, cyli)
00656   sh_1 = geompy.MakeFuse(fuse, sph2)
00657   # As after Fuse we have a compound, we need to obtain a solid from it
00658   #shsh = geompy.SubShapeAll(fuse, geompy.ShapeType["SOLID"])
00659   #sh_1 = shsh[0]
00660   geompy.addToStudy(sh_1, "sh_1")
00661 
00662   # GetShapesOnShape
00663   faces_in_sh = geompy.GetShapesOnShape(sh_1, part, geompy.ShapeType["FACE"],
00664                                         geompy.GEOM.ST_IN)
00665   comp = geompy.MakeCompound(faces_in_sh)
00666   geompy.addToStudy(comp, "Faces of part IN shape sh_1")
00667   if len(faces_in_sh) != 11:
00668     print "Error in GetShapesOnShape()"
00669 
00670   # GetShapesOnShapeAsCompound
00671   faces_in_sh_c = geompy.GetShapesOnShapeAsCompound(sh_1, part, geompy.ShapeType["FACE"],
00672                                                     geompy.GEOM.ST_IN)
00673   geompy.addToStudy(faces_in_sh_c, "Faces of part IN shape sh_1 (as compound)")
00674 
00675   # GetShapesOnShapeIDs
00676   edges_in_sh_ids = geompy.GetShapesOnShapeIDs(sh_1, part, geompy.ShapeType["EDGE"],
00677                                                geompy.GEOM.ST_IN)
00678   edges_in_sh = geompy.CreateGroup(part, geompy.ShapeType["EDGE"])
00679   geompy.UnionIDs(edges_in_sh, edges_in_sh_ids)
00680   geompy.addToStudyInFather(part, edges_in_sh, "Group of edges in shape sh_1")
00681   if len(edges_in_sh_ids) != 15:
00682     print "Error in GetShapesOnShapeIDs()"
00683 
00684   # Prepare arguments for GetInPlace and GetInPlaceByHistory
00685   box5 = geompy.MakeBoxDXDYDZ(100, 100, 100)
00686   box6 = geompy.MakeTranslation(box5, 50, 50, 0)
00687 
00688   geompy.addToStudy(box5, "Box 5")
00689   geompy.addToStudy(box6, "Box 6")
00690 
00691   part = geompy.MakePartition([box5], [box6])
00692   geompy.addToStudy(part, "Partitioned")
00693 
00694   box5_faces = geompy.SubShapeAll(box5, geompy.ShapeType["FACE"])
00695   box6_faces = geompy.SubShapeAll(box6, geompy.ShapeType["FACE"])
00696 
00697   for ifa in range(6):
00698     geompy.addToStudyInFather(box5, box5_faces[ifa], "Face" + `ifa + 1`)
00699     geompy.addToStudyInFather(box6, box6_faces[ifa], "Face" + `ifa + 1`)
00700 
00701   # GetInPlace(theShapeWhere, theShapeWhat)
00702   ibb = 5
00703   faces_list = [box5_faces, box6_faces]
00704   for afaces in faces_list:
00705     ifa = 1
00706     for aface in afaces:
00707       refl_box_face = geompy.GetInPlace(part, aface)
00708       if ibb == 6 and (ifa == 2 or ifa == 4):
00709         # For two faces of the tool box
00710         # there is no reflection in the result.
00711         if refl_box_face is not None:
00712           error = "Result of GetInPlace must be NULL for face "
00713           error += `ifa` + " of box " + `ibb`
00714           raise RuntimeError, error
00715       else:
00716         ssname = "Reflection of face " + `ifa` + " of box " + `ibb`
00717         geompy.addToStudyInFather(part, refl_box_face, ssname)
00718       ifa = ifa + 1
00719     ibb = ibb + 1
00720 
00721   # GetInPlaceByHistory(theShapeWhere, theShapeWhat)
00722   part = geompy.MakePartition([box5], [box6])
00723   geompy.addToStudy(part, "Partitioned")
00724 
00725   ibb = 5
00726   faces_list = [box5_faces, box6_faces]
00727   for afaces in faces_list:
00728     ifa = 1
00729     for aface in afaces:
00730       ssname = "Reflection of face " + `ifa` + " of box " + `ibb` + " (by history)"
00731       if ibb == 6 and (ifa == 2 or ifa == 4):
00732         # use IDL interface directly to avoid error message appearence in Python console
00733         refl_box_face = geompy.ShapesOp.GetInPlaceByHistory(part, aface)
00734         if refl_box_face is not None:
00735           geompy.addToStudyInFather(part, refl_box_face, ssname)
00736           error = "Result of GetInPlaceByHistory must be NULL for face "
00737           error += `ifa` + " of box " + `ibb`
00738           raise RuntimeError, error
00739       else:
00740         # use geompy interface
00741         refl_box_face = geompy.GetInPlaceByHistory(part, aface)
00742         geompy.addToStudyInFather(part, refl_box_face, ssname)
00743       ifa = ifa + 1
00744     ibb = ibb + 1
00745 
00746 #END