Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2000-08-21 |
2 | // Created by: Andrey BETENEV | |
3 | // Copyright (c) 2000-2012 OPEN CASCADE SAS | |
4 | // | |
5 | // The content of this file is subject to the Open CASCADE Technology Public | |
6 | // License Version 6.5 (the "License"). You may not use the content of this file | |
7 | // except in compliance with the License. Please obtain a copy of the License | |
8 | // at http://www.opencascade.org and read it completely before using this file. | |
9 | // | |
10 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its | |
11 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. | |
12 | // | |
13 | // The Original Code and all software distributed under the License is | |
14 | // distributed on an "AS IS" basis, without warranty of any kind, and the | |
15 | // Initial Developer hereby disclaims all such warranties, including without | |
16 | // limitation, any warranties of merchantability, fitness for a particular | |
17 | // purpose or non-infringement. Please see the License for the specific terms | |
18 | // and conditions governing the rights and limitations under the License. | |
19 | ||
7fd59977 | 20 | |
21 | #include <ShapeProcess.ixx> | |
22 | ||
23 | #include <Standard_ErrorHandler.hxx> | |
24 | #include <Standard_Failure.hxx> | |
25 | #include <TCollection_AsciiString.hxx> | |
26 | #include <TColStd_SequenceOfAsciiString.hxx> | |
27 | ||
28 | #include <Message_Msg.hxx> | |
29 | #include <Message_Messenger.hxx> | |
30 | ||
31 | #include <ShapeProcess_Operator.hxx> | |
32 | #include <ShapeProcess_DictionaryOfOperator.hxx> | |
33 | ||
34 | static Handle(ShapeProcess_DictionaryOfOperator) dic; | |
35 | ||
36 | //======================================================================= | |
37 | //function : RegisterOperator | |
38 | //purpose : | |
39 | //======================================================================= | |
40 | ||
41 | Standard_Boolean ShapeProcess::RegisterOperator (const Standard_CString name, | |
42 | const Handle(ShapeProcess_Operator)& op) | |
43 | { | |
44 | if ( dic.IsNull() ) dic = new ShapeProcess_DictionaryOfOperator; | |
45 | if ( dic->HasItem ( name, Standard_True ) ) { | |
46 | #ifdef DEB | |
47 | cout << "Warning: operator with name " << name << " is already registered!" << endl; | |
48 | #endif | |
49 | return Standard_False; | |
50 | } | |
51 | dic->SetItem ( name, op ); | |
52 | return Standard_True; | |
53 | } | |
54 | ||
55 | //======================================================================= | |
56 | //function : FindOperator | |
57 | //purpose : | |
58 | //======================================================================= | |
59 | ||
60 | Standard_Boolean ShapeProcess::FindOperator (const Standard_CString name, | |
61 | Handle(ShapeProcess_Operator)& op) | |
62 | { | |
63 | if ( dic.IsNull() ) dic = new ShapeProcess_DictionaryOfOperator; | |
64 | if ( ! dic->HasItem ( name, Standard_True ) ) { | |
65 | #ifdef DEB | |
66 | cout << "Error: no operator with name " << name << " registered!" << endl; | |
67 | #endif | |
68 | return Standard_False; | |
69 | } | |
70 | op = dic->Item ( name ); | |
71 | return !op.IsNull(); | |
72 | } | |
73 | ||
74 | //======================================================================= | |
75 | //function : Perform | |
76 | //purpose : | |
77 | //======================================================================= | |
78 | ||
79 | Standard_Boolean ShapeProcess::Perform (const Handle(ShapeProcess_Context)& context, | |
80 | const Standard_CString seq) | |
81 | { | |
82 | context->SetScope ( seq ); | |
83 | ||
84 | // get description of the sequence | |
85 | TCollection_AsciiString sequence; | |
86 | if ( ! context->GetString ( "exec.op", sequence ) ) { | |
87 | #ifdef DEB | |
88 | cout << "Error: ShapeProcess_Performer::Perform: sequence not defined for " << seq << endl; | |
89 | #endif | |
90 | context->UnSetScope(); | |
91 | return Standard_False; | |
92 | } | |
93 | TColStd_SequenceOfAsciiString sequenceOfOperators; | |
94 | TCollection_AsciiString oper; | |
95 | Standard_Integer i; | |
96 | for ( i=1; ; i++ ) { | |
97 | oper = sequence.Token ( " \t,;", i ); | |
98 | if ( oper.Length() <=0 ) break; | |
99 | sequenceOfOperators.Append(oper); | |
100 | } | |
101 | ||
102 | // put a message | |
103 | if ( context->TraceLevel() >=2 ) { | |
104 | Message_Msg SMSG0 ("Sequence.MSG0"); //Sequence of operators: %s | |
105 | TCollection_AsciiString Seq; | |
106 | for ( Standard_Integer i1=1; i1 <= sequenceOfOperators.Length(); i1++ ) { | |
107 | if (i1 > 1) Seq += ","; | |
108 | Seq += sequenceOfOperators.Value(i1); | |
109 | } | |
110 | SMSG0.Arg (Seq.ToCString()); | |
111 | context->Messenger()->Send (SMSG0, Message_Info); | |
112 | } | |
113 | ||
114 | // iterate on operators in the sequence | |
115 | for (i=1; i<=sequenceOfOperators.Length(); i++) { | |
116 | oper = sequenceOfOperators.Value(i); | |
117 | ||
118 | if ( context->TraceLevel() >=2 ) { | |
119 | Message_Msg SMSG5 ("Sequence.MSG5"); //Operator %d/%d: %s | |
120 | SMSG5 << i << sequenceOfOperators.Length() << oper.ToCString(); | |
121 | context->Messenger()->Send (SMSG5, Message_Alarm); | |
122 | } | |
123 | ||
124 | Handle(ShapeProcess_Operator) op; | |
125 | if ( ! ShapeProcess::FindOperator ( oper.ToCString(), op ) ) { | |
126 | if ( context->TraceLevel() >0 ) { | |
127 | Message_Msg SMSG1 ("Sequence.MSG1"); //Operator %s not found | |
128 | context->Messenger()->Send (SMSG1 << oper, Message_Alarm); | |
129 | } | |
130 | continue; | |
131 | } | |
132 | ||
133 | context->SetScope ( oper.ToCString() ); | |
134 | try { | |
135 | OCC_CATCH_SIGNALS | |
b485ee79 KD |
136 | if ( !op->Perform(context) ) |
137 | return Standard_False; | |
7fd59977 | 138 | } |
139 | catch (Standard_Failure) { | |
140 | Message_Msg SMSG2 ("Sequence.MSG2"); //Operator %s failed with exception %s | |
141 | SMSG2 << oper << Standard_Failure::Caught()->GetMessageString(); | |
142 | context->Messenger()->Send (SMSG2, Message_Alarm); | |
143 | } | |
144 | context->UnSetScope(); | |
145 | } | |
146 | ||
147 | context->UnSetScope(); | |
148 | return Standard_True; | |
149 | } |