Salome HOME
Merge remote-tracking branch 'origin/Toolbars_Management'
[modules/shaper.git] / test.API / SHAPER / Transformations / TestAPI_Translation.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 from GeomAlgoAPI import GeomAlgoAPI_ShapeAPI as shaperpy
22 from GeomAlgoAPI import GeomAlgoAPI_Exception as myExcept
23 from GeomAPI import GeomAPI_Ax1 as axis
24 from GeomAPI import GeomAPI_Pnt as pnt
25 from GeomAPI import GeomAPI_Dir as direction
26 from GeomAPI import GeomAPI_Shape as shape
27
28 # Points
29 pntOrigin = pnt(0.,0.,0.)
30 pnt1 = pnt(10.,0.,0.)
31 pnt2 = pnt(10.,10.,0.)
32
33 # Axis
34 xDir = direction(10., 0., 0.)
35 ax1 = axis(pntOrigin, xDir)
36
37 yDir = direction(0., 10., 0.)
38 ax2 = axis(pntOrigin, yDir)
39
40 zDir = direction(0., 0., 10.)
41 ax3 = axis(pntOrigin, zDir)
42
43 dir1 = direction(10., 10., 10.)
44 ax4 = axis(pntOrigin, dir1)
45
46 # Boxes
47 Box_1 = shaperpy.makeBox(10., 20., 10.)
48 Box_2 = shaperpy.makeBox(10., 20., 10.)
49 Box_3 = shaperpy.makeBox(10., 20., 10.)
50 Box_4 = shaperpy.makeBox(10., 20., 10.)
51 Box_5 = shaperpy.makeBox(10., 20., 10.)
52 Box_6 = shaperpy.makeBox(10., 20., 10.)
53 Box_7 = shaperpy.makeBox(10., 20., 10.)
54 Box_8 = shaperpy.makeBox(10., 20., 10.)
55 Box_9 = shaperpy.makeBox(10., 20., 10.)
56 Box_10 = shaperpy.makeBox(10., 20., 10.)
57 Box_11 = shaperpy.makeBox(10., 20., 10.)
58 Box_12 = shaperpy.makeBox(10., 20., 10.)
59 Box_13 = shaperpy.makeBox(10., 20., 10.)
60 Box_14 = shaperpy.makeBox(10., 20., 10.)
61 Box_15 = shaperpy.makeBox(10., 20., 10.)
62 Box_16 = shaperpy.makeBox(10., 20., 10.)
63 Box_17 = shaperpy.makeBox(10., 20., 10.)
64 Box_18 = shaperpy.makeBox(10., 20., 10.)
65
66 #Translations "By an axis and a distance"
67 Translation_1 = shaperpy.makeTranslation(Box_1, ax1, 15.)
68 Translation_2 = shaperpy.makeTranslation(Box_2, ax1, 0.)
69 Translation_3 = shaperpy.makeTranslation(Box_3, ax1, -15.)
70
71 try:
72     Translation_4 = shaperpy.makeTranslation(Box_4, None, 15.)
73 except myExcept as ec:
74     assert(ec.what() == "Translation builder :: axis is not valid.")
75
76 Translation_5 = shaperpy.makeTranslation(Box_5, ax4, 15.)
77
78 MultiTranslation_1 = shaperpy.makeMultiTranslation(Box_6, ax1, 15., 3, ax2, 15., 3)
79 Translation_6 = shaperpy.makeTranslation(MultiTranslation_1, ax3, 15.)
80
81 MultiTranslation_2 = shaperpy.makeMultiTranslation(Box_7, ax1, 15., 3, ax2, 15., 3)
82 Translation_7 = shaperpy.makeTranslation(MultiTranslation_2, ax3, 0.)
83
84 MultiTranslation_3 = shaperpy.makeMultiTranslation(Box_8, ax1, 15., 3, ax2, 15., 3)
85 Translation_8 = shaperpy.makeTranslation(MultiTranslation_3, ax3, -15.)
86
87 MultiTranslation_4 = shaperpy.makeMultiTranslation(Box_9, ax1, 15., 3, ax2, 15., 3)
88 try:
89     Translation_9 = shaperpy.makeTranslation(MultiTranslation_4, None, 15.)
90 except myExcept as ec:
91     assert(ec.what() == "Translation builder :: axis is not valid.")
92
93 MultiTranslation_5 = shaperpy.makeMultiTranslation(Box_10, ax1, 15., 3, ax2, 15., 3)
94 Translation_10 = shaperpy.makeTranslation(MultiTranslation_5, ax4, 15.)
95
96 # Translations "By dimensions in X, in Y and in Z"
97 Translation_11 = shaperpy.makeTranslation(Box_11, 10., 20., 15.)
98 Translation_12 = shaperpy.makeTranslation(Box_11, 0., 20., 15.)
99 Translation_13 = shaperpy.makeTranslation(Box_11, 10., 0., 15.)
100 Translation_14 = shaperpy.makeTranslation(Box_11, 10., 20., 0.)
101 Translation_15 = shaperpy.makeTranslation(Box_11, -10., 20., 15.)
102 Translation_16 = shaperpy.makeTranslation(Box_11, 10., -20., 15.)
103 Translation_17 = shaperpy.makeTranslation(Box_11, 10., 20., -15.)
104
105 # Translations "By two points"
106 Translation_18 = shaperpy.makeTranslation(Box_11, pnt1, pnt2)
107
108 try:
109     Translation_19 = shaperpy.makeTranslation(Box_11, pnt1, pnt1)
110 except myExcept as ec:
111     assert(ec.what() == "Translation builder :: start point and end point coincide.")
112
113 try:
114     Translation_20 = shaperpy.makeTranslation(Box_11, None, pnt1)
115 except myExcept as ec:
116     assert(ec.what() == "Translation builder :: start point is not valid.")
117
118 try:
119     Translation_21 = shaperpy.makeTranslation(Box_11, pnt1, None)
120 except myExcept as ec:
121     assert(ec.what() == "Translation builder :: end point is not valid.")
122
123 try:
124     Translation_22 = shaperpy.makeTranslation(None, ax1, 15.)
125 except myExcept as ec:
126     assert(ec.what() == "Translation builder :: source shape is not valid.")
127
128 try:
129     Translation_23 = shaperpy.makeTranslation(None, 10., 20., 15.)
130 except myExcept as ec:
131     assert(ec.what() == "Translation builder :: source shape is not valid.")
132
133 try:
134     Translation_24 = shaperpy.makeTranslation(None, pnt1, pnt2)
135 except myExcept as ec:
136     assert(ec.what() == "Translation builder :: source shape is invalid.")
137
138 try:
139     Translation_25 = shaperpy.makeTranslation(shape(), ax1, 15.)
140 except myExcept as ec:
141     assert(ec.what() == "Translation builder :: source shape does not contain any actual shape.")