1 // File: ShapeProcess.cxx
2 // Created: Mon Aug 21 19:03:02 2000
3 // Author: Andrey BETENEV
4 // <abv@doomox.nnov.matra-dtv.fr>
6 #include <ShapeProcess.ixx>
8 #include <Standard_ErrorHandler.hxx>
9 #include <Standard_Failure.hxx>
10 #include <TCollection_AsciiString.hxx>
11 #include <TColStd_SequenceOfAsciiString.hxx>
13 #include <Message_Msg.hxx>
14 #include <Message_Messenger.hxx>
16 #include <ShapeProcess_Operator.hxx>
17 #include <ShapeProcess_DictionaryOfOperator.hxx>
19 static Handle(ShapeProcess_DictionaryOfOperator) dic;
21 //=======================================================================
22 //function : RegisterOperator
24 //=======================================================================
26 Standard_Boolean ShapeProcess::RegisterOperator (const Standard_CString name,
27 const Handle(ShapeProcess_Operator)& op)
29 if ( dic.IsNull() ) dic = new ShapeProcess_DictionaryOfOperator;
30 if ( dic->HasItem ( name, Standard_True ) ) {
32 cout << "Warning: operator with name " << name << " is already registered!" << endl;
34 return Standard_False;
36 dic->SetItem ( name, op );
40 //=======================================================================
41 //function : FindOperator
43 //=======================================================================
45 Standard_Boolean ShapeProcess::FindOperator (const Standard_CString name,
46 Handle(ShapeProcess_Operator)& op)
48 if ( dic.IsNull() ) dic = new ShapeProcess_DictionaryOfOperator;
49 if ( ! dic->HasItem ( name, Standard_True ) ) {
51 cout << "Error: no operator with name " << name << " registered!" << endl;
53 return Standard_False;
55 op = dic->Item ( name );
59 //=======================================================================
62 //=======================================================================
64 Standard_Boolean ShapeProcess::Perform (const Handle(ShapeProcess_Context)& context,
65 const Standard_CString seq)
67 context->SetScope ( seq );
69 // get description of the sequence
70 TCollection_AsciiString sequence;
71 if ( ! context->GetString ( "exec.op", sequence ) ) {
73 cout << "Error: ShapeProcess_Performer::Perform: sequence not defined for " << seq << endl;
75 context->UnSetScope();
76 return Standard_False;
78 TColStd_SequenceOfAsciiString sequenceOfOperators;
79 TCollection_AsciiString oper;
82 oper = sequence.Token ( " \t,;", i );
83 if ( oper.Length() <=0 ) break;
84 sequenceOfOperators.Append(oper);
88 if ( context->TraceLevel() >=2 ) {
89 Message_Msg SMSG0 ("Sequence.MSG0"); //Sequence of operators: %s
90 TCollection_AsciiString Seq;
91 for ( Standard_Integer i1=1; i1 <= sequenceOfOperators.Length(); i1++ ) {
92 if (i1 > 1) Seq += ",";
93 Seq += sequenceOfOperators.Value(i1);
95 SMSG0.Arg (Seq.ToCString());
96 context->Messenger()->Send (SMSG0, Message_Info);
99 // iterate on operators in the sequence
100 for (i=1; i<=sequenceOfOperators.Length(); i++) {
101 oper = sequenceOfOperators.Value(i);
103 if ( context->TraceLevel() >=2 ) {
104 Message_Msg SMSG5 ("Sequence.MSG5"); //Operator %d/%d: %s
105 SMSG5 << i << sequenceOfOperators.Length() << oper.ToCString();
106 context->Messenger()->Send (SMSG5, Message_Alarm);
109 Handle(ShapeProcess_Operator) op;
110 if ( ! ShapeProcess::FindOperator ( oper.ToCString(), op ) ) {
111 if ( context->TraceLevel() >0 ) {
112 Message_Msg SMSG1 ("Sequence.MSG1"); //Operator %s not found
113 context->Messenger()->Send (SMSG1 << oper, Message_Alarm);
118 context->SetScope ( oper.ToCString() );
121 if ( !op->Perform(context) )
122 return Standard_False;
124 catch (Standard_Failure) {
125 Message_Msg SMSG2 ("Sequence.MSG2"); //Operator %s failed with exception %s
126 SMSG2 << oper << Standard_Failure::Caught()->GetMessageString();
127 context->Messenger()->Send (SMSG2, Message_Alarm);
129 context->UnSetScope();
132 context->UnSetScope();
133 return Standard_True;