1 // Copyright (C) 2014-2015 OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "CANRECPluginImpl_Driver.hxx"
20 #include "CANRECPluginImpl_Types.hxx"
21 #include "CANRECPluginImpl_ICanRec.hxx"
23 #include <GEOM_Function.hxx>
25 #include <BRepOffsetAPI_Sewing.hxx>
26 #include <Standard_Version.hxx>
27 #include <TFunction_Logbook.hxx>
28 #include <ShapeConvert_CanonicAPI.hxx>
29 #include <ShapeConvert_UnionFaces.hxx>
30 #include <ShapeConvert_UnionEdges.hxx>
32 #ifdef CANREC_HASLICENSE
33 #include "CANRECPluginImpl_license.h"
34 #include <OCCLicense_Activate.hxx>
35 #include <Standard_LicenseError.hxx>
36 #endif // CANREC_HASLICENSE
38 const Standard_GUID& CANRECPluginImpl_Driver::GetID()
40 static Standard_GUID aGUID("7e1492bb-b4cd-4a40-ad8f-102902b0047e");
44 CANRECPluginImpl_Driver::CANRECPluginImpl_Driver()
48 CANRECPluginImpl_Driver::~CANRECPluginImpl_Driver()
52 Standard_Boolean CANRECPluginImpl_Driver::MustExecute( const TFunction_Logbook& ) const
57 void CANRECPluginImpl_Driver::Validate( TFunction_Logbook& ) const
61 Standard_Integer CANRECPluginImpl_Driver::Execute( TFunction_Logbook& log ) const
63 if ( Label().IsNull() ) return 0;
64 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction( Label() );
66 CANRECPluginImpl_ICanRec aData( aFunction );
69 bool isNeedMergeSurf = aData.GetNeedMergeSurf();
70 bool isNeedMergeCurves = aData.GetNeedMergeCurves();
71 double aTolerance = aData.GetTolerance();
72 Handle(GEOM_Function) anObject = aData.GetObject();
73 TopoDS_Shape aShape = anObject->GetValue();
75 #ifdef CANREC_HASLICENSE
77 OCCLicense_Activate( "CANREC-"OCC_VERSION_STRING, CANREC_LICENSE );
79 catch (Standard_LicenseError) {
82 #endif // CANREC_HASLICENSE
84 ShapeConvert_CanonicAPI aRecognizer;
85 aRecognizer.Tolerance() = aTolerance;
86 aRecognizer.SurfaceMode() = isNeedMergeSurf;
87 aRecognizer.CurveMode() = isNeedMergeCurves;
90 aRecognizer.SetShape( aShape );
91 aRecognizer.UnifyMode() = false;
92 aRecognizer.Perform();
93 TopoDS_Shape aResultingShape = aRecognizer.Shape();
96 BRepOffsetAPI_Sewing aSewing( aTolerance );
97 aSewing.Add( aResultingShape );
99 aResultingShape = aSewing.SewedShape();
101 // 3.1. Union Surfaces
102 if ( isNeedMergeSurf ) {
103 ShapeConvert_UnionFaces aFaceUnifier;
104 aFaceUnifier.GetTolerance() = aTolerance;
105 aResultingShape = aFaceUnifier.Perform( aResultingShape );
109 if ( isNeedMergeCurves ) {
110 ShapeConvert_UnionEdges anEdgeUnifier;
111 aResultingShape = anEdgeUnifier.Perform( aResultingShape, aTolerance );
114 if ( aResultingShape.IsNull() ) return 0;
116 aFunction->SetValue( aResultingShape );
118 log.SetTouched( Label() );
123 bool CANRECPluginImpl_Driver::
124 GetCreationInformation( std::string& theOperationName,
125 std::vector<GEOM_Param>& theParams )
127 if ( Label().IsNull() ) return 0;
128 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction( Label() );
130 CANRECPluginImpl_ICanRec aCI( aFunction );
132 theOperationName = "CANONICALRECOGNITION";
133 AddParam( theParams, PLUGIN_NAME, "CANRECPlugin" );
134 AddParam( theParams, "Tolerance", aCI.GetTolerance() );
135 AddParam( theParams, "Merge Surfaces", aCI.GetNeedMergeSurf() );
136 AddParam( theParams, "Merge Curves", aCI.GetNeedMergeCurves() );
141 IMPLEMENT_STANDARD_HANDLE( CANRECPluginImpl_Driver, GEOM_BaseDriver );
142 IMPLEMENT_STANDARD_RTTIEXT( CANRECPluginImpl_Driver, GEOM_BaseDriver );