Salome HOME
47d31ae2425b75442f2c70c16f99ead87fbf5e65
[modules/geom.git] / src / GEOM_I / GEOM_IBlocksOperations_i.cc
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include <Standard_Stream.hxx>
24
25 #include "GEOM_IBlocksOperations_i.hh"
26
27 #include "utilities.h"
28 #include "OpUtil.hxx"
29 #include "Utils_ExceptHandlers.hxx"
30
31 #include "GEOM_Engine.hxx"
32 #include "GEOM_Object.hxx"
33
34 #include <TColStd_HSequenceOfTransient.hxx>
35 #include <TColStd_HArray1OfInteger.hxx>
36
37 //=============================================================================
38 /*!
39  *   constructor:
40  */
41 //=============================================================================
42 GEOM_IBlocksOperations_i::GEOM_IBlocksOperations_i (PortableServer::POA_ptr thePOA,
43                                                     GEOM::GEOM_Gen_ptr theEngine,
44                                                     ::GEOMImpl_IBlocksOperations* theImpl)
45 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
46 {
47   MESSAGE("GEOM_IBlocksOperations_i::GEOM_IBlocksOperations_i");
48 }
49
50 //=============================================================================
51 /*!
52  *  destructor
53  */
54 //=============================================================================
55 GEOM_IBlocksOperations_i::~GEOM_IBlocksOperations_i()
56 {
57   MESSAGE("GEOM_IBlocksOperations_i::~GEOM_IBlocksOperations_i");
58 }
59
60
61 //=============================================================================
62 /*!
63  *  MakeQuad
64  */
65 //=============================================================================
66 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::MakeQuad
67                (GEOM::GEOM_Object_ptr theEdge1, GEOM::GEOM_Object_ptr theEdge2,
68                 GEOM::GEOM_Object_ptr theEdge3, GEOM::GEOM_Object_ptr theEdge4)
69 {
70   GEOM::GEOM_Object_var aGEOMObject;
71
72   //Set a not done flag
73   GetOperations()->SetNotDone();
74
75   //Get the reference edges
76   Handle(::GEOM_Object) anEdge1 = GetObjectImpl(theEdge1);
77   Handle(::GEOM_Object) anEdge2 = GetObjectImpl(theEdge2);
78   Handle(::GEOM_Object) anEdge3 = GetObjectImpl(theEdge3);
79   Handle(::GEOM_Object) anEdge4 = GetObjectImpl(theEdge4);
80
81   if (anEdge1.IsNull() || anEdge2.IsNull() ||
82       anEdge3.IsNull() || anEdge4.IsNull()) return aGEOMObject._retn();
83
84   //Create the Face
85   Handle(::GEOM_Object) anObject =
86     GetOperations()->MakeQuad(anEdge1, anEdge2, anEdge3, anEdge4);
87   if (!GetOperations()->IsDone() || anObject.IsNull())
88     return aGEOMObject._retn();
89
90   return GetObject(anObject);
91 }
92
93 //=============================================================================
94 /*!
95  *  MakeQuad2Edges
96  */
97 //=============================================================================
98 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::MakeQuad2Edges
99                (GEOM::GEOM_Object_ptr theEdge1, GEOM::GEOM_Object_ptr theEdge2)
100 {
101   GEOM::GEOM_Object_var aGEOMObject;
102
103   //Set a not done flag
104   GetOperations()->SetNotDone();
105
106   //Get the reference edges
107   Handle(::GEOM_Object) anEdge1 = GetObjectImpl(theEdge1);
108   Handle(::GEOM_Object) anEdge2 = GetObjectImpl(theEdge2);
109
110   if (anEdge1.IsNull() || anEdge2.IsNull()) return aGEOMObject._retn();
111
112   //Create the Face
113   Handle(::GEOM_Object) anObject =
114     GetOperations()->MakeQuad2Edges(anEdge1, anEdge2);
115   if (!GetOperations()->IsDone() || anObject.IsNull())
116     return aGEOMObject._retn();
117
118   return GetObject(anObject);
119 }
120
121 //=============================================================================
122 /*!
123  *  MakeQuad4Vertices
124  */
125 //=============================================================================
126 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::MakeQuad4Vertices
127                       (GEOM::GEOM_Object_ptr thePnt1, GEOM::GEOM_Object_ptr thePnt2,
128                        GEOM::GEOM_Object_ptr thePnt3, GEOM::GEOM_Object_ptr thePnt4)
129 {
130   GEOM::GEOM_Object_var aGEOMObject;
131
132   //Set a not done flag
133   GetOperations()->SetNotDone();
134
135   //Get the reference points
136   Handle(::GEOM_Object) aPnt1 = GetObjectImpl(thePnt1);
137   Handle(::GEOM_Object) aPnt2 = GetObjectImpl(thePnt2);
138   Handle(::GEOM_Object) aPnt3 = GetObjectImpl(thePnt3);
139   Handle(::GEOM_Object) aPnt4 = GetObjectImpl(thePnt4);
140
141   if (aPnt1.IsNull() || aPnt2.IsNull() ||
142       aPnt3.IsNull() || aPnt4.IsNull()) return aGEOMObject._retn();
143
144   //Create the Face
145   Handle(::GEOM_Object) anObject =
146     GetOperations()->MakeQuad4Vertices(aPnt1, aPnt2, aPnt3, aPnt4);
147   if (!GetOperations()->IsDone() || anObject.IsNull())
148     return aGEOMObject._retn();
149
150   return GetObject(anObject);
151 }
152
153 //=============================================================================
154 /*!
155  *  MakeHexa
156  */
157 //=============================================================================
158 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::MakeHexa
159                (GEOM::GEOM_Object_ptr theFace1, GEOM::GEOM_Object_ptr theFace2,
160                 GEOM::GEOM_Object_ptr theFace3, GEOM::GEOM_Object_ptr theFace4,
161                 GEOM::GEOM_Object_ptr theFace5, GEOM::GEOM_Object_ptr theFace6)
162 {
163   GEOM::GEOM_Object_var aGEOMObject;
164
165   //Set a not done flag
166   GetOperations()->SetNotDone();
167
168   //Get the reference Faces
169   Handle(::GEOM_Object) anFace1 = GetObjectImpl(theFace1);
170   Handle(::GEOM_Object) anFace2 = GetObjectImpl(theFace2);
171   Handle(::GEOM_Object) anFace3 = GetObjectImpl(theFace3);
172   Handle(::GEOM_Object) anFace4 = GetObjectImpl(theFace4);
173   Handle(::GEOM_Object) anFace5 = GetObjectImpl(theFace5);
174   Handle(::GEOM_Object) anFace6 = GetObjectImpl(theFace6);
175
176   if (anFace1.IsNull() || anFace2.IsNull() ||
177       anFace3.IsNull() || anFace4.IsNull() ||
178       anFace5.IsNull() || anFace6.IsNull()) return aGEOMObject._retn();
179
180   //Create the Face
181   Handle(::GEOM_Object) anObject = GetOperations()->MakeHexa
182     (anFace1, anFace2, anFace3, anFace4, anFace5, anFace6);
183   if (!GetOperations()->IsDone() || anObject.IsNull())
184     return aGEOMObject._retn();
185
186   return GetObject(anObject);
187 }
188
189 //=============================================================================
190 /*!
191  *  MakeHexa2Faces
192  */
193 //=============================================================================
194 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::MakeHexa2Faces
195                (GEOM::GEOM_Object_ptr theFace1, GEOM::GEOM_Object_ptr theFace2)
196 {
197   GEOM::GEOM_Object_var aGEOMObject;
198
199   //Set a not done flag
200   GetOperations()->SetNotDone();
201
202   //Get the reference Faces
203   Handle(::GEOM_Object) anFace1 = GetObjectImpl(theFace1);
204   Handle(::GEOM_Object) anFace2 = GetObjectImpl(theFace2);
205
206   if (anFace1.IsNull() || anFace2.IsNull()) return aGEOMObject._retn();
207
208   //Create the Face
209   Handle(::GEOM_Object) anObject =
210     GetOperations()->MakeHexa2Faces(anFace1, anFace2);
211   if (!GetOperations()->IsDone() || anObject.IsNull())
212     return aGEOMObject._retn();
213
214   return GetObject(anObject);
215 }
216
217 //=============================================================================
218 /*!
219  *  MakeBlockCompound
220  */
221 //=============================================================================
222 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::MakeBlockCompound
223                                             (GEOM::GEOM_Object_ptr theCompound)
224 {
225   GEOM::GEOM_Object_var aGEOMObject;
226
227   //Set a not done flag
228   GetOperations()->SetNotDone();
229
230   //Get the reference Compound
231   Handle(::GEOM_Object) aCompound = GetObjectImpl(theCompound);
232   if (aCompound.IsNull()) return aGEOMObject._retn();
233
234   //Create the Blocks Compound
235   Handle(::GEOM_Object) anObject =
236     GetOperations()->MakeBlockCompound(aCompound);
237   if (!GetOperations()->IsDone() || anObject.IsNull())
238     return aGEOMObject._retn();
239
240   return GetObject(anObject);
241 }
242
243 //=============================================================================
244 /*!
245  *  GetPoint
246  */
247 //=============================================================================
248 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetPoint (GEOM::GEOM_Object_ptr theShape,
249                                                           const CORBA::Double   theX,
250                                                           const CORBA::Double   theY,
251                                                           const CORBA::Double   theZ,
252                                                           const CORBA::Double   theEpsilon)
253 {
254   GEOM::GEOM_Object_var aGEOMObject;
255
256   //Set a not done flag
257   GetOperations()->SetNotDone();
258
259   //Get the reference Objects
260   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
261   if (aShape.IsNull()) return aGEOMObject._retn();
262
263   //Create the Point
264   Handle(::GEOM_Object) anObject =
265     GetOperations()->GetPoint(aShape, theX, theY, theZ, theEpsilon);
266   if (!GetOperations()->IsDone() || anObject.IsNull())
267     return aGEOMObject._retn();
268
269   return GetObject(anObject);
270 }
271
272 //=============================================================================
273 /*!
274  *  GetVertexNearPoint
275  */
276 //=============================================================================
277 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetVertexNearPoint
278                                                 (GEOM::GEOM_Object_ptr theShape,
279                                                  GEOM::GEOM_Object_ptr thePoint)
280 {
281   GEOM::GEOM_Object_var aGEOMObject;
282
283   // Set a not done flag
284   GetOperations()->SetNotDone();
285
286   // Get the reference Objects
287   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
288   Handle(::GEOM_Object) aPoint = GetObjectImpl(thePoint);
289   if (aShape.IsNull() || aPoint.IsNull()) return aGEOMObject._retn();
290
291   // Create the Point
292   Handle(::GEOM_Object) anObject =
293     GetOperations()->GetVertexNearPoint(aShape, aPoint);
294   if (!GetOperations()->IsDone() || anObject.IsNull())
295     return aGEOMObject._retn();
296
297   return GetObject(anObject);
298 }
299
300 //=============================================================================
301 /*!
302  *  GetEdge
303  */
304 //=============================================================================
305 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetEdge (GEOM::GEOM_Object_ptr theShape,
306                                                          GEOM::GEOM_Object_ptr thePoint1,
307                                                          GEOM::GEOM_Object_ptr thePoint2)
308 {
309   GEOM::GEOM_Object_var aGEOMObject;
310
311   //Set a not done flag
312   GetOperations()->SetNotDone();
313
314   //Get the reference Objects
315   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
316   Handle(::GEOM_Object) aPoint1 = GetObjectImpl(thePoint1);
317   Handle(::GEOM_Object) aPoint2 = GetObjectImpl(thePoint2);
318
319   if (aShape.IsNull() ||
320       aPoint1.IsNull() || aPoint2.IsNull()) return aGEOMObject._retn();
321
322   //Create the Point
323   Handle(::GEOM_Object) anObject =
324     GetOperations()->GetEdge(aShape, aPoint1, aPoint2);
325   if (!GetOperations()->IsDone() || anObject.IsNull())
326     return aGEOMObject._retn();
327
328   return GetObject(anObject);
329 }
330
331 //=============================================================================
332 /*!
333  *  GetEdgeNearPoint
334  */
335 //=============================================================================
336 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetEdgeNearPoint (GEOM::GEOM_Object_ptr theShape,
337                                                                   GEOM::GEOM_Object_ptr thePoint)
338 {
339   GEOM::GEOM_Object_var aGEOMObject;
340
341   //Set a not done flag
342   GetOperations()->SetNotDone();
343
344   //Get the reference Objects
345   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
346   Handle(::GEOM_Object) aPoint = GetObjectImpl(thePoint);
347
348   if (aShape.IsNull() || aPoint.IsNull()) return aGEOMObject._retn();
349
350   //Create the Edge
351   Handle(::GEOM_Object) anObject =
352     GetOperations()->GetEdgeNearPoint(aShape, aPoint);
353   if (!GetOperations()->IsDone() || anObject.IsNull())
354     return aGEOMObject._retn();
355
356   return GetObject(anObject);
357 }
358
359 //=============================================================================
360 /*!
361  *  GetFaceByPoints
362  */
363 //=============================================================================
364 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetFaceByPoints
365                                               (GEOM::GEOM_Object_ptr theShape,
366                                                GEOM::GEOM_Object_ptr thePoint1,
367                                                GEOM::GEOM_Object_ptr thePoint2,
368                                                GEOM::GEOM_Object_ptr thePoint3,
369                                                GEOM::GEOM_Object_ptr thePoint4)
370 {
371   GEOM::GEOM_Object_var aGEOMObject;
372
373   //Set a not done flag
374   GetOperations()->SetNotDone();
375
376   //Get the reference Objects
377   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
378   Handle(::GEOM_Object) aPoint1 = GetObjectImpl(thePoint1);
379   Handle(::GEOM_Object) aPoint2 = GetObjectImpl(thePoint2);
380   Handle(::GEOM_Object) aPoint3 = GetObjectImpl(thePoint3);
381   Handle(::GEOM_Object) aPoint4 = GetObjectImpl(thePoint4);
382
383   if (aShape.IsNull() ||
384       aPoint1.IsNull() || aPoint2.IsNull() ||
385       aPoint3.IsNull() || aPoint4.IsNull()) return aGEOMObject._retn();
386
387   //Create the Face
388   Handle(::GEOM_Object) anObject =
389     GetOperations()->GetFaceByPoints(aShape, aPoint1, aPoint2, aPoint3, aPoint4);
390   if (!GetOperations()->IsDone() || anObject.IsNull())
391     return aGEOMObject._retn();
392
393   return GetObject(anObject);
394 }
395
396 //=============================================================================
397 /*!
398  *  GetFaceByEdges
399  */
400 //=============================================================================
401 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetFaceByEdges
402                                                (GEOM::GEOM_Object_ptr theShape,
403                                                 GEOM::GEOM_Object_ptr theEdge1,
404                                                 GEOM::GEOM_Object_ptr theEdge2)
405 {
406   GEOM::GEOM_Object_var aGEOMObject;
407
408   //Set a not done flag
409   GetOperations()->SetNotDone();
410
411   //Get the reference Objects
412   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
413   Handle(::GEOM_Object) anEdge1 = GetObjectImpl(theEdge1);
414   Handle(::GEOM_Object) anEdge2 = GetObjectImpl(theEdge2);
415
416   if (aShape.IsNull() ||
417       anEdge1.IsNull() || anEdge2.IsNull()) return aGEOMObject._retn();
418
419   //Create the Face
420   Handle(::GEOM_Object) anObject =
421     GetOperations()->GetFaceByEdges(aShape, anEdge1, anEdge2);
422   if (!GetOperations()->IsDone() || anObject.IsNull())
423     return aGEOMObject._retn();
424
425   return GetObject(anObject);
426 }
427
428 //=============================================================================
429 /*!
430  *  GetOppositeFace
431  */
432 //=============================================================================
433 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetOppositeFace (GEOM::GEOM_Object_ptr theShape,
434                                                                  GEOM::GEOM_Object_ptr theFace)
435 {
436   GEOM::GEOM_Object_var aGEOMObject;
437
438   //Set a not done flag
439   GetOperations()->SetNotDone();
440
441   //Get the reference Objects
442   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
443   Handle(::GEOM_Object) aFace = GetObjectImpl(theFace);
444
445   if (aShape.IsNull() || aFace.IsNull()) return aGEOMObject._retn();
446
447   //Create the Face
448   Handle(::GEOM_Object) anObject =
449     GetOperations()->GetOppositeFace(aShape, aFace);
450   if (!GetOperations()->IsDone() || anObject.IsNull())
451     return aGEOMObject._retn();
452
453   return GetObject(anObject);
454 }
455
456 //=============================================================================
457 /*!
458  *  GetFaceNearPoint
459  */
460 //=============================================================================
461 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetFaceNearPoint (GEOM::GEOM_Object_ptr theShape,
462                                                                   GEOM::GEOM_Object_ptr thePoint)
463 {
464   GEOM::GEOM_Object_var aGEOMObject;
465
466   //Set a not done flag
467   GetOperations()->SetNotDone();
468
469   //Get the reference Objects
470   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
471   Handle(::GEOM_Object) aPoint = GetObjectImpl(thePoint);
472
473   if (aShape.IsNull() || aPoint.IsNull()) return aGEOMObject._retn();
474
475   //Create the Face
476   Handle(::GEOM_Object) anObject =
477     GetOperations()->GetFaceNearPoint(aShape, aPoint);
478   if (!GetOperations()->IsDone() || anObject.IsNull())
479     return aGEOMObject._retn();
480
481   return GetObject(anObject);
482 }
483
484 //=============================================================================
485 /*!
486  *  GetFaceByNormale
487  */
488 //=============================================================================
489 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetFaceByNormale (GEOM::GEOM_Object_ptr theShape,
490                                                                   GEOM::GEOM_Object_ptr theVector)
491 {
492   GEOM::GEOM_Object_var aGEOMObject;
493
494   //Set a not done flag
495   GetOperations()->SetNotDone();
496
497   //Get the reference Objects
498   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
499   Handle(::GEOM_Object) aVector = GetObjectImpl(theVector);
500
501   if (aShape.IsNull() || aVector.IsNull()) return aGEOMObject._retn();
502
503   //Create the Face
504   Handle(::GEOM_Object) anObject =
505     GetOperations()->GetFaceByNormale(aShape, aVector);
506   if (!GetOperations()->IsDone() || anObject.IsNull())
507     return aGEOMObject._retn();
508
509   return GetObject(anObject);
510 }
511
512 //=============================================================================
513 /*!
514  *  GetShapesNearPoint
515  */
516 //=============================================================================
517 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetShapesNearPoint
518                       (GEOM::GEOM_Object_ptr theShape,
519                        GEOM::GEOM_Object_ptr thePoint,
520                        CORBA::Long           theShapeType,
521                        CORBA::Double         theTolerance)
522 {
523   GEOM::GEOM_Object_var aGEOMObject;
524
525   // Set a not done flag
526   GetOperations()->SetNotDone();
527
528   // Get the reference Objects
529   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
530   Handle(::GEOM_Object) aPoint = GetObjectImpl(thePoint);
531
532   if (aShape.IsNull() || aPoint.IsNull()) return aGEOMObject._retn();
533
534   // Create the Shape
535   Handle(::GEOM_Object) anObject =
536     GetOperations()->GetShapesNearPoint(aShape, aPoint, theShapeType, theTolerance);
537   if (!GetOperations()->IsDone() || anObject.IsNull())
538     return aGEOMObject._retn();
539
540   return GetObject(anObject);
541 }
542
543 //=============================================================================
544 /*!
545  *  ExplodeCompoundOfBlocks
546  */
547 //=============================================================================
548 GEOM::ListOfGO* GEOM_IBlocksOperations_i::ExplodeCompoundOfBlocks
549                                           (GEOM::GEOM_Object_ptr theCompound,
550                                            const CORBA::Long     theMinNbFaces,
551                                            const CORBA::Long     theMaxNbFaces)
552 {
553   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
554
555   //Set a not done flag
556   GetOperations()->SetNotDone();
557
558   //Get the reference Compound
559   Handle(::GEOM_Object) aCompound = GetObjectImpl(theCompound);
560   if (aCompound.IsNull()) return aSeq._retn();
561
562   //Explode
563   Handle(TColStd_HSequenceOfTransient) aHSeq =
564     GetOperations()->ExplodeCompoundOfBlocks(aCompound, theMinNbFaces, theMaxNbFaces);
565   if (!GetOperations()->IsDone() || aHSeq.IsNull())
566     return aSeq._retn();
567
568   Standard_Integer aLength = aHSeq->Length();
569   aSeq->length(aLength);
570   for (Standard_Integer i = 1; i <= aLength; i++)
571     aSeq[i-1] = GetObject(Handle(::GEOM_Object)::DownCast(aHSeq->Value(i)));
572
573   return aSeq._retn();
574 }
575
576 //=============================================================================
577 /*!
578  *  IsCompoundOfBlocks
579  */
580 //=============================================================================
581 CORBA::Boolean GEOM_IBlocksOperations_i::IsCompoundOfBlocks
582                                           (GEOM::GEOM_Object_ptr theCompound,
583                                            const CORBA::Long     theMinNbFaces,
584                                            const CORBA::Long     theMaxNbFaces,
585                                            CORBA::Long&          theNbBlocks)
586 {
587   theNbBlocks = 0;
588   CORBA::Boolean isComp = false;
589
590   //Set a not done flag
591   GetOperations()->SetNotDone();
592
593   //Get the reference Compound
594   Handle(::GEOM_Object) aCompound = GetObjectImpl(theCompound);
595   if (aCompound.IsNull()) return isComp;
596
597   //Check
598   Standard_Integer nbBlocks = 0;
599   isComp = GetOperations()->IsCompoundOfBlocks(aCompound,
600                                                theMinNbFaces,
601                                                theMaxNbFaces,
602                                                nbBlocks);
603   if (!GetOperations()->IsDone())
604     return isComp;
605
606   theNbBlocks = nbBlocks;
607   return isComp;
608 }
609
610 //=============================================================================
611 /*!
612  *  CheckCompoundOfBlocks
613  */
614 //=============================================================================
615 CORBA::Boolean GEOM_IBlocksOperations_i::CheckCompoundOfBlocks
616                                           (GEOM::GEOM_Object_ptr theCompound,
617                                            const CORBA::Double   theToleranceC1,
618                                            GEOM::GEOM_IBlocksOperations::BCErrors_out theErrors)
619 {
620   CORBA::Boolean isComp = false;
621
622   //Set a not done flag
623   GetOperations()->SetNotDone();
624
625   //Get the reference Compound
626   Handle(::GEOM_Object) aCompound = GetObjectImpl(theCompound);
627   if (aCompound.IsNull()) return isComp;
628
629   GEOM::GEOM_IBlocksOperations::BCErrors_var anErrArray =
630     new GEOM::GEOM_IBlocksOperations::BCErrors();
631
632   //Check
633   std::list<GEOMImpl_IBlocksOperations::BCError> errList;
634   isComp = GetOperations()->CheckCompoundOfBlocks
635     (aCompound, theToleranceC1, errList);
636   if (!GetOperations()->IsDone()) {
637     anErrArray->length(0);
638     theErrors = anErrArray._retn();
639     return isComp;
640   }
641
642   const int nbErr = errList.size();
643   anErrArray->length(nbErr);
644
645   // fill the local CORBA array with values from lists
646   std::list<GEOMImpl_IBlocksOperations::BCError>::iterator errIt = errList.begin();
647   int i = 0;
648   for (; errIt != errList.end(); i++, errIt++) {
649     GEOM::GEOM_IBlocksOperations::BCError_var anError =
650       new GEOM::GEOM_IBlocksOperations::BCError();
651
652     GEOMImpl_IBlocksOperations::BCError errStruct = *errIt;
653
654     switch (errStruct.error) {
655     case GEOMImpl_IBlocksOperations::NOT_BLOCK:
656       anError->error = GEOM::GEOM_IBlocksOperations::NOT_BLOCK;
657       break;
658     case GEOMImpl_IBlocksOperations::EXTRA_EDGE:
659       anError->error = GEOM::GEOM_IBlocksOperations::EXTRA_EDGE;
660       break;
661     case GEOMImpl_IBlocksOperations::INVALID_CONNECTION:
662       anError->error = GEOM::GEOM_IBlocksOperations::INVALID_CONNECTION;
663       break;
664     case GEOMImpl_IBlocksOperations::NOT_CONNECTED:
665       anError->error = GEOM::GEOM_IBlocksOperations::NOT_CONNECTED;
666       break;
667     case GEOMImpl_IBlocksOperations::NOT_GLUED:
668       anError->error = GEOM::GEOM_IBlocksOperations::NOT_GLUED;
669       break;
670     default:
671       break;
672     }
673
674     std::list<int> sshList = errStruct.incriminated;
675     GEOM::ListOfLong_var anIncrims = new GEOM::ListOfLong();
676     anIncrims->length(sshList.size());
677
678     std::list<int>::iterator sshIt = sshList.begin();
679     int jj = 0;
680     for (; sshIt != sshList.end(); jj++, sshIt++) {
681       anIncrims[jj] = *sshIt;
682     }
683
684     anError->incriminated = anIncrims;
685
686     anErrArray[i] = anError;
687   }
688
689   // initialize out-parameter with local array
690   theErrors = anErrArray._retn();
691
692   return isComp;
693 }
694
695 //=============================================================================
696 /*!
697  *  PrintBCErrors
698  */
699 //=============================================================================
700 char* GEOM_IBlocksOperations_i::PrintBCErrors
701                       (GEOM::GEOM_Object_ptr theCompound,
702                        const GEOM::GEOM_IBlocksOperations::BCErrors& theErrors)
703 {
704   //Get the reference Compound
705   Handle(::GEOM_Object) aCompound = GetObjectImpl(theCompound);
706   if (aCompound.IsNull()) return NULL;
707
708   // Convert the errors sequence
709   std::list<GEOMImpl_IBlocksOperations::BCError> anErrors;
710   int nbErr = theErrors.length();
711   int ie = 0;
712   for (; ie < nbErr; ie++) {
713     const GEOM::GEOM_IBlocksOperations::BCError err = theErrors[ie];
714     const GEOM::GEOM_IBlocksOperations::BCErrorType typ = err.error;
715     const GEOM::ListOfLong incrims = err.incriminated;
716
717     GEOMImpl_IBlocksOperations::BCError errStruct;
718     switch (typ) {
719     case GEOM::GEOM_IBlocksOperations::NOT_BLOCK:
720       errStruct.error = GEOMImpl_IBlocksOperations::NOT_BLOCK;
721       break;
722     case GEOM::GEOM_IBlocksOperations::EXTRA_EDGE:
723       errStruct.error = GEOMImpl_IBlocksOperations::EXTRA_EDGE;
724       break;
725     case GEOM::GEOM_IBlocksOperations::INVALID_CONNECTION:
726       errStruct.error = GEOMImpl_IBlocksOperations::INVALID_CONNECTION;
727       break;
728     case GEOM::GEOM_IBlocksOperations::NOT_CONNECTED:
729       errStruct.error = GEOMImpl_IBlocksOperations::NOT_CONNECTED;
730       break;
731     case GEOM::GEOM_IBlocksOperations::NOT_GLUED:
732       errStruct.error = GEOMImpl_IBlocksOperations::NOT_GLUED;
733       break;
734     default:
735       break;
736     }
737
738     int ii = 0;
739     int aLen = incrims.length();
740     for (; ii < aLen; ii++) {
741       errStruct.incriminated.push_back(incrims[ii]);
742     }
743
744     anErrors.push_back(errStruct);
745   }
746
747   TCollection_AsciiString aDescr = GetOperations()->PrintBCErrors(aCompound, anErrors);
748   return CORBA::string_dup(aDescr.ToCString());
749 }
750
751 //=============================================================================
752 /*!
753  *  GetNonBlocks
754  */
755 //=============================================================================
756 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetNonBlocks
757                                       (GEOM::GEOM_Object_ptr theShape,
758                                        const CORBA::Double   theToleranceC1,
759                                        GEOM::GEOM_Object_out theNonQuads)
760 {
761   GEOM::GEOM_Object_var aGEOMObject;
762   GEOM::GEOM_Object_var aNonQuads;
763
764   theNonQuads = aNonQuads._retn();
765
766   //Set a not done flag
767   GetOperations()->SetNotDone();
768
769   //Get the reference Objects
770   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
771   if (aShape.IsNull()) return aGEOMObject._retn();
772
773   //Get the result
774   Handle(::GEOM_Object) aFaces;
775   Handle(::GEOM_Object) anObject =
776     GetOperations()->GetNonBlocks(aShape, theToleranceC1, aFaces);
777   if (!GetOperations()->IsDone())
778     return aGEOMObject._retn();
779
780   if (!aFaces.IsNull())
781     theNonQuads = GetObject(aFaces);
782
783   if (anObject.IsNull())
784     return aGEOMObject._retn();
785
786   return GetObject(anObject);
787 }
788
789 //=============================================================================
790 /*!
791  *  RemoveExtraEdges
792  */
793 //=============================================================================
794 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::RemoveExtraEdges
795                                       (GEOM::GEOM_Object_ptr theShape,
796                                        CORBA::Long           theOptimumNbFaces)
797 {
798   GEOM::GEOM_Object_var aGEOMObject;
799
800   //Set a not done flag
801   GetOperations()->SetNotDone();
802
803   //Get the reference Objects
804   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
805   if (aShape.IsNull()) return aGEOMObject._retn();
806
807   //Get the result
808   Handle(::GEOM_Object) anObject = GetOperations()->RemoveExtraEdges(aShape, theOptimumNbFaces);
809   if (!GetOperations()->IsDone() || anObject.IsNull())
810     return aGEOMObject._retn();
811
812   return GetObject(anObject);
813 }
814
815 //=============================================================================
816 /*!
817  *  UnionFaces
818  */
819 //=============================================================================
820 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::UnionFaces
821                                       (GEOM::GEOM_Object_ptr theShape)
822 {
823   GEOM::GEOM_Object_var aGEOMObject;
824
825   //Set a not done flag
826   GetOperations()->SetNotDone();
827
828   //Get the reference Objects
829   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
830   if (aShape.IsNull()) return aGEOMObject._retn();
831
832   //Get the result
833   Handle(::GEOM_Object) anObject = GetOperations()->UnionFaces(aShape);
834   if (!GetOperations()->IsDone() || anObject.IsNull())
835     return aGEOMObject._retn();
836
837   return GetObject(anObject);
838 }
839
840 //=============================================================================
841 /*!
842  *  CheckAndImprove
843  */
844 //=============================================================================
845 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::CheckAndImprove (GEOM::GEOM_Object_ptr theCompound)
846 {
847   GEOM::GEOM_Object_var aGEOMObject;
848
849   //Set a not done flag
850   GetOperations()->SetNotDone();
851
852   //Get the reference Objects
853   Handle(::GEOM_Object) aCompound = GetObjectImpl(theCompound);
854   if (aCompound.IsNull()) return aGEOMObject._retn();
855
856   //Get the result
857   Handle(::GEOM_Object) anObject =
858     GetOperations()->CheckAndImprove(aCompound);
859   if (!GetOperations()->IsDone() || anObject.IsNull())
860     return aGEOMObject._retn();
861
862   return GetObject(anObject);
863 }
864
865 //=============================================================================
866 /*!
867  *  GetBlockNearPoint
868  */
869 //=============================================================================
870 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetBlockNearPoint (GEOM::GEOM_Object_ptr theCompound,
871                                                                    GEOM::GEOM_Object_ptr thePoint)
872 {
873   GEOM::GEOM_Object_var aGEOMObject;
874
875   //Set a not done flag
876   GetOperations()->SetNotDone();
877
878   //Get the reference Objects
879   Handle(::GEOM_Object) aCompound = GetObjectImpl(theCompound);
880   Handle(::GEOM_Object) aPoint = GetObjectImpl(thePoint);
881
882   if (aCompound.IsNull() || aPoint.IsNull()) return aGEOMObject._retn();
883
884   //Get the block
885   Handle(::GEOM_Object) anObject =
886     GetOperations()->GetBlockNearPoint(aCompound, aPoint);
887   if (!GetOperations()->IsDone() || anObject.IsNull())
888     return aGEOMObject._retn();
889
890   return GetObject(anObject);
891 }
892
893 //=============================================================================
894 /*!
895  *  GetBlockByParts
896  */
897 //=============================================================================
898 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetBlockByParts (GEOM::GEOM_Object_ptr theCompound,
899                                                                  const GEOM::ListOfGO& theParts)
900 {
901   GEOM::GEOM_Object_var aGEOMObject;
902
903   //Set a not done flag
904   GetOperations()->SetNotDone();
905
906   //Get the reference Compound
907   Handle(::GEOM_Object) aCompound = GetObjectImpl(theCompound);
908   if (aCompound.IsNull()) return aGEOMObject._retn();
909
910   //Get the parts
911   int ind, aLen;
912   Handle(TColStd_HSequenceOfTransient) aParts = new TColStd_HSequenceOfTransient;
913
914   aLen = theParts.length();
915   for (ind = 0; ind < aLen; ind++) {
916     Handle(::GEOM_Object) aSh = GetObjectImpl(theParts[ind]);
917     if (aSh.IsNull()) return aGEOMObject._retn();
918     aParts->Append(aSh);
919   }
920
921   //Get the Block
922   Handle(::GEOM_Object) anObject =
923     GetOperations()->GetBlockByParts(aCompound, aParts);
924   if (!GetOperations()->IsDone() || anObject.IsNull())
925     return aGEOMObject._retn();
926
927   return GetObject(anObject);
928 }
929
930 //=============================================================================
931 /*!
932  *  GetBlocksByParts
933  */
934 //=============================================================================
935 GEOM::ListOfGO* GEOM_IBlocksOperations_i::GetBlocksByParts (GEOM::GEOM_Object_ptr theCompound,
936                                                             const GEOM::ListOfGO& theParts)
937 {
938   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
939
940   //Set a not done flag
941   GetOperations()->SetNotDone();
942
943   //Get the reference Compound
944   Handle(::GEOM_Object) aCompound = GetObjectImpl(theCompound);
945   if (aCompound.IsNull()) return aSeq._retn();
946
947   //Get the parts
948   int ind, aLen;
949   Handle(TColStd_HSequenceOfTransient) aParts = new TColStd_HSequenceOfTransient;
950
951   aLen = theParts.length();
952   for (ind = 0; ind < aLen; ind++) {
953     Handle(::GEOM_Object) aSh = GetObjectImpl(theParts[ind]);
954     if (aSh.IsNull()) return aSeq._retn();
955     aParts->Append(aSh);
956   }
957
958   //Get the Block
959   Handle(TColStd_HSequenceOfTransient) aHSeq =
960     GetOperations()->GetBlocksByParts(aCompound, aParts);
961   if (!GetOperations()->IsDone() || aHSeq.IsNull())
962     return aSeq._retn();
963
964   Standard_Integer aLength = aHSeq->Length();
965   aSeq->length(aLength);
966   for (Standard_Integer i = 1; i <= aLength; i++)
967     aSeq[i-1] = GetObject(Handle(::GEOM_Object)::DownCast(aHSeq->Value(i)));
968
969   return aSeq._retn();
970 }
971
972 //=============================================================================
973 /*!
974  *  MakeMultiTransformation1D
975  */
976 //=============================================================================
977 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::MakeMultiTransformation1D
978                                               (GEOM::GEOM_Object_ptr theBlock,
979                                                const CORBA::Long     theDirFace1,
980                                                const CORBA::Long     theDirFace2,
981                                                const CORBA::Long     theNbTimes)
982 {
983   GEOM::GEOM_Object_var aGEOMObject;
984
985   //Set a not done flag
986   GetOperations()->SetNotDone();
987
988   //Get the object itself and the vector of translation
989   Handle(::GEOM_Object) aBasicObject = GetObjectImpl(theBlock);
990   if (aBasicObject.IsNull()) return aGEOMObject._retn();
991
992   //Perform the transformation
993   Handle(::GEOM_Object) anObject = GetOperations()->MakeMultiTransformation1D
994     (aBasicObject, theDirFace1, theDirFace2, theNbTimes);
995   if (!GetOperations()->IsDone() || anObject.IsNull())  return aGEOMObject._retn();
996
997   return GetObject(anObject);
998 }
999
1000 //=============================================================================
1001 /*!
1002  *  MakeMultiTransformation2D
1003  */
1004 //=============================================================================
1005 GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::MakeMultiTransformation2D
1006                                            (GEOM::GEOM_Object_ptr theBlock,
1007                                             const CORBA::Long     theDirFace1U,
1008                                             const CORBA::Long     theDirFace2U,
1009                                             const CORBA::Long     theNbTimesU,
1010                                             const CORBA::Long     theDirFace1V,
1011                                             const CORBA::Long     theDirFace2V,
1012                                             const CORBA::Long     theNbTimesV)
1013 {
1014   GEOM::GEOM_Object_var aGEOMObject;
1015
1016   //Set a not done flag
1017   GetOperations()->SetNotDone();
1018
1019   //Get the object itself
1020   Handle(::GEOM_Object) aBasicObject = GetObjectImpl(theBlock);
1021   if (aBasicObject.IsNull()) return aGEOMObject._retn();
1022
1023   //Perform the transformation
1024   Handle(::GEOM_Object) anObject = GetOperations()->MakeMultiTransformation2D
1025     (aBasicObject,
1026      theDirFace1U, theDirFace2U, theNbTimesU,
1027      theDirFace1V, theDirFace2V, theNbTimesV);
1028   if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
1029
1030   return GetObject(anObject);
1031 }
1032
1033 //=============================================================================
1034 /*!
1035  *  Propagate
1036  */
1037 //=============================================================================
1038 GEOM::ListOfGO* GEOM_IBlocksOperations_i::Propagate (GEOM::GEOM_Object_ptr theShape)
1039 {
1040   GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
1041
1042   //Set a not done flag
1043   GetOperations()->SetNotDone();
1044
1045   //Get the reference Shape
1046   Handle(::GEOM_Object) aShape = GetObjectImpl(theShape);
1047   if (aShape.IsNull()) return aSeq._retn();
1048
1049   //Get the Propagation chains
1050   Handle(TColStd_HSequenceOfTransient) aHSeq =
1051     GetOperations()->Propagate(aShape);
1052   if (!GetOperations()->IsDone() || aHSeq.IsNull())
1053     return aSeq._retn();
1054
1055   Standard_Integer aLength = aHSeq->Length();
1056   aSeq->length(aLength);
1057   for (Standard_Integer i = 1; i <= aLength; i++)
1058     aSeq[i-1] = GetObject(Handle(::GEOM_Object)::DownCast(aHSeq->Value(i)));
1059
1060   return aSeq._retn();
1061 }