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 <NCollection_DataMap.hxx>
17 #include <Message_Messenger.hxx>
18 #include <Message_Msg.hxx>
19 #include <ShapeProcess.hxx>
20 #include <ShapeProcess_Context.hxx>
21 #include <ShapeProcess_Operator.hxx>
22 #include <Standard_ErrorHandler.hxx>
23 #include <Standard_Failure.hxx>
24 #include <TCollection_AsciiString.hxx>
25 #include <TColStd_SequenceOfAsciiString.hxx>
27 static NCollection_DataMap<TCollection_AsciiString, Handle(ShapeProcess_Operator)> aMapOfOperators;
28 //=======================================================================
29 //function : RegisterOperator
31 //=======================================================================
33 Standard_Boolean ShapeProcess::RegisterOperator (const Standard_CString name,
34 const Handle(ShapeProcess_Operator)& op)
36 if (aMapOfOperators.IsBound(name)) {
38 cout << "Warning: operator with name " << name << " is already registered!" << endl;
40 return Standard_False;
42 aMapOfOperators.Bind( name, op );
46 //=======================================================================
47 //function : FindOperator
49 //=======================================================================
51 Standard_Boolean ShapeProcess::FindOperator (const Standard_CString name,
52 Handle(ShapeProcess_Operator)& op)
54 if (!aMapOfOperators.IsBound(name)) {
56 cout << "Error: no operator with name " << name << " registered!" << endl;
58 return Standard_False;
60 op = aMapOfOperators.ChangeFind(name);
64 //=======================================================================
67 //=======================================================================
69 Standard_Boolean ShapeProcess::Perform (const Handle(ShapeProcess_Context)& context,
70 const Standard_CString seq)
72 context->SetScope ( seq );
74 // get description of the sequence
75 TCollection_AsciiString sequence;
76 if ( ! context->GetString ( "exec.op", sequence ) ) {
78 cout << "Error: ShapeProcess_Performer::Perform: sequence not defined for " << seq << endl;
80 if ( context->TraceLevel() >0 ) {
81 Message_Msg SMSG3 ("SP.Sequence.Warn.NoSeq"); // Sequence %s not found
82 context->Messenger()->Send (SMSG3 << seq, Message_Warning);
84 context->UnSetScope();
85 return Standard_False;
87 TColStd_SequenceOfAsciiString sequenceOfOperators;
88 TCollection_AsciiString oper;
91 oper = sequence.Token ( " \t,;", i );
92 if ( oper.Length() <=0 ) break;
93 sequenceOfOperators.Append(oper);
97 if ( context->TraceLevel() >=2 ) {
98 Message_Msg SMSG0 ("SP.Sequence.Info.Seq"); //Sequence of operators: %s
99 TCollection_AsciiString Seq;
100 for ( Standard_Integer i1=1; i1 <= sequenceOfOperators.Length(); i1++ ) {
101 if (i1 > 1) Seq += ",";
102 Seq += sequenceOfOperators.Value(i1);
104 SMSG0.Arg (Seq.ToCString());
105 context->Messenger()->Send (SMSG0, Message_Info);
108 // iterate on operators in the sequence
109 Standard_Boolean isDone = Standard_False;
110 for (i=1; i<=sequenceOfOperators.Length(); i++) {
111 oper = sequenceOfOperators.Value(i);
113 if ( context->TraceLevel() >=2 ) {
114 Message_Msg SMSG5 ("SP.Sequence.Info.Operator"); //Operator %d/%d: %s
115 SMSG5 << i << sequenceOfOperators.Length() << oper.ToCString();
116 context->Messenger()->Send (SMSG5, Message_Alarm);
119 Handle(ShapeProcess_Operator) op;
120 if ( ! ShapeProcess::FindOperator ( oper.ToCString(), op ) ) {
121 if ( context->TraceLevel() >0 ) {
122 Message_Msg SMSG1 ("SP.Sequence.Error.NoOp"); //Operator %s not found
123 context->Messenger()->Send (SMSG1 << oper, Message_Alarm);
128 context->SetScope ( oper.ToCString() );
131 if ( op->Perform(context) )
132 isDone = Standard_True;
134 catch (Standard_Failure const& anException) {
135 Message_Msg SMSG2 ("SP.Sequence.Error.Except"); //Operator %s failed with exception %s
136 SMSG2 << oper << anException.GetMessageString();
137 context->Messenger()->Send (SMSG2, Message_Alarm);
139 context->UnSetScope();
142 context->UnSetScope();