Commit | Line | Data |
---|---|---|
7fd59977 | 1 | // File: ShapeProcess.cxx |
2 | // Created: Mon Aug 21 19:03:02 2000 | |
3 | // Author: Andrey BETENEV | |
4 | // <abv@doomox.nnov.matra-dtv.fr> | |
5 | ||
6 | #include <ShapeProcess.ixx> | |
7 | ||
8 | #include <Standard_ErrorHandler.hxx> | |
9 | #include <Standard_Failure.hxx> | |
10 | #include <TCollection_AsciiString.hxx> | |
11 | #include <TColStd_SequenceOfAsciiString.hxx> | |
12 | ||
13 | #include <Message_Msg.hxx> | |
14 | #include <Message_Messenger.hxx> | |
15 | ||
16 | #include <ShapeProcess_Operator.hxx> | |
17 | #include <ShapeProcess_DictionaryOfOperator.hxx> | |
18 | ||
19 | static Handle(ShapeProcess_DictionaryOfOperator) dic; | |
20 | ||
21 | //======================================================================= | |
22 | //function : RegisterOperator | |
23 | //purpose : | |
24 | //======================================================================= | |
25 | ||
26 | Standard_Boolean ShapeProcess::RegisterOperator (const Standard_CString name, | |
27 | const Handle(ShapeProcess_Operator)& op) | |
28 | { | |
29 | if ( dic.IsNull() ) dic = new ShapeProcess_DictionaryOfOperator; | |
30 | if ( dic->HasItem ( name, Standard_True ) ) { | |
31 | #ifdef DEB | |
32 | cout << "Warning: operator with name " << name << " is already registered!" << endl; | |
33 | #endif | |
34 | return Standard_False; | |
35 | } | |
36 | dic->SetItem ( name, op ); | |
37 | return Standard_True; | |
38 | } | |
39 | ||
40 | //======================================================================= | |
41 | //function : FindOperator | |
42 | //purpose : | |
43 | //======================================================================= | |
44 | ||
45 | Standard_Boolean ShapeProcess::FindOperator (const Standard_CString name, | |
46 | Handle(ShapeProcess_Operator)& op) | |
47 | { | |
48 | if ( dic.IsNull() ) dic = new ShapeProcess_DictionaryOfOperator; | |
49 | if ( ! dic->HasItem ( name, Standard_True ) ) { | |
50 | #ifdef DEB | |
51 | cout << "Error: no operator with name " << name << " registered!" << endl; | |
52 | #endif | |
53 | return Standard_False; | |
54 | } | |
55 | op = dic->Item ( name ); | |
56 | return !op.IsNull(); | |
57 | } | |
58 | ||
59 | //======================================================================= | |
60 | //function : Perform | |
61 | //purpose : | |
62 | //======================================================================= | |
63 | ||
64 | Standard_Boolean ShapeProcess::Perform (const Handle(ShapeProcess_Context)& context, | |
65 | const Standard_CString seq) | |
66 | { | |
67 | context->SetScope ( seq ); | |
68 | ||
69 | // get description of the sequence | |
70 | TCollection_AsciiString sequence; | |
71 | if ( ! context->GetString ( "exec.op", sequence ) ) { | |
72 | #ifdef DEB | |
73 | cout << "Error: ShapeProcess_Performer::Perform: sequence not defined for " << seq << endl; | |
74 | #endif | |
75 | context->UnSetScope(); | |
76 | return Standard_False; | |
77 | } | |
78 | TColStd_SequenceOfAsciiString sequenceOfOperators; | |
79 | TCollection_AsciiString oper; | |
80 | Standard_Integer i; | |
81 | for ( i=1; ; i++ ) { | |
82 | oper = sequence.Token ( " \t,;", i ); | |
83 | if ( oper.Length() <=0 ) break; | |
84 | sequenceOfOperators.Append(oper); | |
85 | } | |
86 | ||
87 | // put a message | |
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); | |
94 | } | |
95 | SMSG0.Arg (Seq.ToCString()); | |
96 | context->Messenger()->Send (SMSG0, Message_Info); | |
97 | } | |
98 | ||
99 | // iterate on operators in the sequence | |
100 | for (i=1; i<=sequenceOfOperators.Length(); i++) { | |
101 | oper = sequenceOfOperators.Value(i); | |
102 | ||
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); | |
107 | } | |
108 | ||
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); | |
114 | } | |
115 | continue; | |
116 | } | |
117 | ||
118 | context->SetScope ( oper.ToCString() ); | |
119 | try { | |
120 | OCC_CATCH_SIGNALS | |
b485ee79 KD |
121 | if ( !op->Perform(context) ) |
122 | return Standard_False; | |
7fd59977 | 123 | } |
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); | |
128 | } | |
129 | context->UnSetScope(); | |
130 | } | |
131 | ||
132 | context->UnSetScope(); | |
133 | return Standard_True; | |
134 | } |