1 // Created on: 2000-08-21
2 // Created by: Andrey BETENEV
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <ShapeProcess.hxx>
18 #include <NCollection_DataMap.hxx>
19 #include <Message_Messenger.hxx>
20 #include <Message_Msg.hxx>
21 #include <Message_ProgressScope.hxx>
22 #include <ShapeProcess_Context.hxx>
23 #include <ShapeProcess_Operator.hxx>
24 #include <Standard_ErrorHandler.hxx>
25 #include <Standard_Failure.hxx>
26 #include <TCollection_AsciiString.hxx>
27 #include <TColStd_SequenceOfAsciiString.hxx>
29 static NCollection_DataMap<TCollection_AsciiString, Handle(ShapeProcess_Operator)> aMapOfOperators;
30 //=======================================================================
31 //function : RegisterOperator
33 //=======================================================================
35 Standard_Boolean ShapeProcess::RegisterOperator (const Standard_CString name,
36 const Handle(ShapeProcess_Operator)& op)
38 if (aMapOfOperators.IsBound(name)) {
40 std::cout << "Warning: operator with name " << name << " is already registered!" << std::endl;
42 return Standard_False;
44 aMapOfOperators.Bind( name, op );
48 //=======================================================================
49 //function : FindOperator
51 //=======================================================================
53 Standard_Boolean ShapeProcess::FindOperator (const Standard_CString name,
54 Handle(ShapeProcess_Operator)& op)
56 if (!aMapOfOperators.IsBound(name)) {
58 std::cout << "Error: no operator with name " << name << " registered!" << std::endl;
60 return Standard_False;
62 op = aMapOfOperators.ChangeFind(name);
66 //=======================================================================
69 //=======================================================================
71 Standard_Boolean ShapeProcess::Perform (const Handle(ShapeProcess_Context)& context,
72 const Standard_CString seq,
73 const Message_ProgressRange& theProgress)
75 context->SetScope ( seq );
77 // get description of the sequence
78 TCollection_AsciiString sequence;
79 if ( ! context->GetString ( "exec.op", sequence ) ) {
81 std::cout << "Error: ShapeProcess_Performer::Perform: sequence not defined for " << seq << std::endl;
83 if ( context->TraceLevel() >0 ) {
84 Message_Msg SMSG3 ("SP.Sequence.Warn.NoSeq"); // Sequence %s not found
85 context->Messenger()->Send (SMSG3 << seq, Message_Warning);
87 context->UnSetScope();
88 return Standard_False;
90 TColStd_SequenceOfAsciiString sequenceOfOperators;
91 TCollection_AsciiString oper;
94 oper = sequence.Token ( " \t,;", i );
95 if ( oper.Length() <=0 ) break;
96 sequenceOfOperators.Append(oper);
100 if ( context->TraceLevel() >=2 ) {
101 Message_Msg SMSG0 ("SP.Sequence.Info.Seq"); //Sequence of operators: %s
102 TCollection_AsciiString Seq;
103 for ( Standard_Integer i1=1; i1 <= sequenceOfOperators.Length(); i1++ ) {
104 if (i1 > 1) Seq += ",";
105 Seq += sequenceOfOperators.Value(i1);
107 SMSG0.Arg (Seq.ToCString());
108 context->Messenger()->Send (SMSG0, Message_Info);
111 // iterate on operators in the sequence
112 Standard_Boolean isDone = Standard_False;
113 Message_ProgressScope aPS(theProgress, NULL, sequenceOfOperators.Length());
114 for (i = 1; i<=sequenceOfOperators.Length() && aPS.More(); i++)
116 oper = sequenceOfOperators.Value(i);
117 Message_ProgressRange aRange = aPS.Next();
119 if ( context->TraceLevel() >=2 ) {
120 Message_Msg SMSG5 ("SP.Sequence.Info.Operator"); //Operator %d/%d: %s
121 SMSG5 << i << sequenceOfOperators.Length() << oper.ToCString();
122 context->Messenger()->Send (SMSG5, Message_Alarm);
125 Handle(ShapeProcess_Operator) op;
126 if ( ! ShapeProcess::FindOperator ( oper.ToCString(), op ) ) {
127 if ( context->TraceLevel() >0 ) {
128 Message_Msg SMSG1 ("SP.Sequence.Error.NoOp"); //Operator %s not found
129 context->Messenger()->Send (SMSG1 << oper, Message_Alarm);
134 context->SetScope ( oper.ToCString() );
137 if (op->Perform(context, aRange))
138 isDone = Standard_True;
140 catch (Standard_Failure const& anException) {
141 Message_Msg SMSG2 ("SP.Sequence.Error.Except"); //Operator %s failed with exception %s
142 SMSG2 << oper << anException.GetMessageString();
143 context->Messenger()->Send (SMSG2, Message_Alarm);
145 context->UnSetScope();
148 context->UnSetScope();