Salome HOME
Merge remote branch 'origin/V7_dev'
[plugins/canrecplugin.git] / src / CANRECPLUGINEngine / CANRECPluginEngine_IOperations_i.cc
1 // Copyright (C) 2014-2016  OPEN CASCADE
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 email : webmaster.salome@opencascade.com
18 //
19
20 #include "CANRECPluginEngine_IOperations_i.hh"
21 #include "CANRECPluginImpl_IOperations.hxx"
22
23 #include <utilities.h>
24
25 CANRECPluginEngine_IOperations_i::CANRECPluginEngine_IOperations_i( PortableServer::POA_ptr thePOA, 
26                                                                     GEOM::GEOM_Gen_ptr theEngine, 
27                                                                     CANRECPluginImpl_IOperations* theImpl )
28   : GEOM_IOperations_i( thePOA, theEngine, theImpl )
29 {
30   MESSAGE( "CANRECPluginEngine_IOperations_i::CANRECPluginEngine_IOperations_i()" );
31 }
32
33 CANRECPluginEngine_IOperations_i::~CANRECPluginEngine_IOperations_i()
34 {
35   MESSAGE( "CANRECPluginEngine_IOperations_i::~CANRECPluginEngine_IOperations_i()" );
36 }
37
38 //=============================================================================
39 /*!
40  *  Create a canonical recognition for the object
41  *  \param theMergeSurf set merging surfaces
42  *  \param theMergeCurves set merging curves
43  *  \param theTolerance set tolerance
44  *  \param theObject is initial object
45  *  \return New GEOM_Object, containing the created shape.
46  */
47 //=============================================================================
48 GEOM::GEOM_Object_ptr
49 CANRECPluginEngine_IOperations_i::MakeCanonicalRecognition( GEOM::GEOM_Object_ptr theObject,
50                                                             CORBA::Boolean theMergeSurf,
51                                                             CORBA::Boolean theMergeCurves,
52                                                             CORBA::Double theTolerance,
53                                                             CANRECPlugin::ListOfLong_out theStat )
54 {
55   theStat = new CANRECPlugin::ListOfLong();
56
57   // Set a not done flag
58   GetOperations()->SetNotDone();
59
60   // Get the reference points
61   HANDLE_NAMESPACE(GEOM_Object) anInitObject = GetObjectImpl( theObject );
62
63   if ( anInitObject.IsNull() ) {
64     return GEOM::GEOM_Object::_nil();
65   }
66
67   // Make Canonical Recognition
68   Handle(TColStd_HSequenceOfInteger) aStat    = new TColStd_HSequenceOfInteger;
69   HANDLE_NAMESPACE(GEOM_Object)      anObject =
70         GetOperations()->MakeCanonicalRecognition(anInitObject,
71                                                   theMergeSurf, 
72                                                   theMergeCurves, 
73                                                   theTolerance,
74                                                   aStat);
75
76   if (!GetOperations()->IsDone() || anObject.IsNull()) {
77     return GEOM::GEOM_Object::_nil();
78   }
79
80   // Copy statistics.
81   int nbInts = aStat->Length();
82   int i;
83
84   theStat->length(nbInts);
85
86   for (i = 0; i < nbInts; i++) {
87     theStat[i] = aStat->Value(i + 1);
88   }
89
90   return GetObject( anObject );
91 }
92
93 //=============================================================================
94 /*!
95  *  \brief Get the number of canonical faces in the shape. 
96  *
97  *  \param theObject the input object (solid, compound, compsolid).
98  *
99  *  \return the number of canonical faces in the object.
100  */
101 //=============================================================================
102 CORBA::Long CANRECPluginEngine_IOperations_i::GetNbCanonicalFaces
103                               (GEOM::GEOM_Object_ptr theObject)
104 {
105   // Set a not done flag
106   GetOperations()->SetNotDone();
107
108   // Get the reference points
109   HANDLE_NAMESPACE(GEOM_Object) anInitObject = GetObjectImpl(theObject);
110
111   if (anInitObject.IsNull()) {
112     return -1;
113   }
114
115   // Get the number of canonical faces.
116   CORBA::Long aResult = GetOperations()->GetNbCanonicalFaces(anInitObject);
117
118   if (!GetOperations()->IsDone()) {
119     return -1;
120   }
121
122   return aResult;
123 }
124
125 ::CANRECPluginImpl_IOperations* CANRECPluginEngine_IOperations_i::GetOperations()
126 {
127   return (::CANRECPluginImpl_IOperations*)GetImpl();
128 }