0030686: Visualization, SelectMgr_ViewerSelector - sorting issues of transformation...
[occt.git] / src / XSControl / XSControl_Controller.hxx
1 // Created on: 1995-03-13
2 // Created by: Christian CAILLET
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef _XSControl_Controller_HeaderFile
18 #define _XSControl_Controller_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
22
23 #include <TCollection_AsciiString.hxx>
24 #include <TColStd_SequenceOfTransient.hxx>
25 #include <TColStd_HSequenceOfHAsciiString.hxx>
26 #include <TColStd_SequenceOfInteger.hxx>
27 #include <Interface_HArray1OfHAsciiString.hxx>
28 #include <Standard_Transient.hxx>
29 #include <NCollection_Vector.hxx>
30 #include <IFSelect_ReturnStatus.hxx>
31 #include <Standard_Transient.hxx>
32 #include <NCollection_DataMap.hxx>
33 #include <TCollection_AsciiString.hxx>
34 class IFSelect_WorkLibrary;
35 class Interface_Protocol;
36 class IFSelect_Signature;
37 class Transfer_ActorOfTransientProcess;
38 class Transfer_ActorOfFinderProcess;
39 class Standard_DomainError;
40 class XSControl_WorkSession;
41 class Interface_InterfaceModel;
42 class Transfer_FinderProcess;
43 class TopoDS_Shape;
44 class Interface_CheckIterator;
45
46
47 class XSControl_Controller;
48 DEFINE_STANDARD_HANDLE(XSControl_Controller, Standard_Transient)
49
50 //! This class allows a general X-STEP engine to run generic
51 //! functions on any interface norm, in the same way. It includes
52 //! the transfer operations. I.e. it gathers the already available
53 //! general modules, the engine has just to know it
54 //!
55 //! The important point is that a given X-STEP Controller is
56 //! attached to a given couple made of an Interface Norm (such as
57 //! IGES-5.1) and an application data model (CasCade Shapes for
58 //! instance).
59 //!
60 //! Finally, Controller can be gathered in a general dictionary then
61 //! retreived later by a general call (method Recorded)
62 //!
63 //! It does not manage the produced data, but the Actors make the
64 //! link between the norm and the application
65 class XSControl_Controller : public Standard_Transient
66 {
67  public:
68   
69   //! Changes names
70   //! if a name is empty, the formerly set one remains
71   //! Remark : Does not call Record or AutoRecord
72   Standard_EXPORT void SetNames (const Standard_CString theLongName, const Standard_CString theShortName);
73   
74   //! Records <me> is a general dictionary under Short and Long
75   //! Names (see method Name)
76   void AutoRecord() const
77   {
78     Record (Name(Standard_True));
79     Record (Name(Standard_False));
80   }
81   
82   //! Records <me> in a general dictionary under a name
83   //! Error if <name> already used for another one
84   Standard_EXPORT void Record (const Standard_CString name) const;
85   
86   //! Returns the Controller attached to a given name
87   //! Returns a Null Handle if <name> is unknown
88   Standard_EXPORT static Handle(XSControl_Controller) Recorded (const Standard_CString name);
89   
90   //! Returns a name, as given when initializing :
91   //! rsc = False (D) : True Name attached to the Norm (long name)
92   //! rsc = True : Name of the ressource set (i.e. short name)
93   Standard_CString Name (const Standard_Boolean rsc = Standard_False) const
94   { return (rsc ? myShortName.ToCString() : myLongName.ToCString()); }
95   
96   //! Returns the Protocol attached to the Norm (from field)
97   const Handle(Interface_Protocol) & Protocol () const
98   { return myAdaptorProtocol; }
99   
100   //! Returns the SignType attached to the norm (from field)
101   //szv:const Handle(IFSelect_Signature) & SignType1() const
102   //szv:{ return mySignType; }
103   
104   //! Returns the WorkLibrary attached to the Norm. Remark that it
105   //! has to be in phase with the Protocol  (read from field)
106   const Handle(IFSelect_WorkLibrary) & WorkLibrary() const
107   { return myAdaptorLibrary; }
108   
109   //! Creates a new empty Model ready to receive data of the Norm
110   //! Used to write data from Imagine to an interface file
111   Standard_EXPORT virtual Handle(Interface_InterfaceModel) NewModel() const = 0;
112   
113   //! Returns the Actor for Read attached to the pair (norm,appli)
114   //! It can be adapted for data of the input Model, as required
115   //! Can be read from field then adapted with Model as required
116   Standard_EXPORT virtual Handle(Transfer_ActorOfTransientProcess) ActorRead (const Handle(Interface_InterfaceModel)& model) const;
117   
118   //! Returns the Actor for Write attached to the pair (norm,appli)
119   //! Read from field. Can be redefined
120   Standard_EXPORT virtual Handle(Transfer_ActorOfFinderProcess) ActorWrite() const;
121   
122   //! Sets mininum and maximum values for modetrans (write)
123   //! Erases formerly recorded bounds and values
124   //! Actually only for shape
125   //! Then, for each value a little help can be attached
126   Standard_EXPORT void SetModeWrite (const Standard_Integer modemin, const Standard_Integer modemax, const Standard_Boolean shape = Standard_True);
127   
128   //! Attaches a short line of help to a value of modetrans (write)
129   Standard_EXPORT void SetModeWriteHelp (const Standard_Integer modetrans, const Standard_CString help, const Standard_Boolean shape = Standard_True);
130   
131   //! Returns recorded min and max values for modetrans (write)
132   //! Actually only for shapes
133   //! Returns True if bounds are set, False else (then, free value)
134   Standard_EXPORT Standard_Boolean ModeWriteBounds (Standard_Integer& modemin, Standard_Integer& modemax, const Standard_Boolean shape = Standard_True) const;
135   
136   //! Tells if a value of <modetrans> is a good value(within bounds)
137   //! Actually only for shapes
138   Standard_EXPORT Standard_Boolean IsModeWrite (const Standard_Integer modetrans, const Standard_Boolean shape = Standard_True) const;
139   
140   //! Returns the help line recorded for a value of modetrans
141   //! empty if help not defined or not within bounds or if values are free
142   Standard_EXPORT Standard_CString ModeWriteHelp (const Standard_Integer modetrans, const Standard_Boolean shape = Standard_True) const;
143   
144   //! Tells if <obj> (an application object) is a valid candidate
145   //! for a transfer to a Model.
146   //! By default, asks the ActorWrite if known (through a
147   //! TransientMapper). Can be redefined
148   Standard_EXPORT virtual Standard_Boolean RecognizeWriteTransient (const Handle(Standard_Transient)& obj, const Standard_Integer modetrans = 0) const;
149   
150   //! Takes one Transient Object and transfers it to an
151   //! InterfaceModel (already created, e.g. by NewModel)
152   //! (result is recorded in the model by AddWithRefs)
153   //! FP records produced results and checks
154   //!
155   //! Default uses ActorWrite; can be redefined as necessary
156   //! Returned value is a status, as follows :
157   //! 0  OK ,  1 No Result ,  2 Fail (e.g. exception raised)
158   //! -1 bad conditions ,  -2 bad model or null model
159   //! For type of object not recognized : should return 1
160   Standard_EXPORT virtual IFSelect_ReturnStatus TransferWriteTransient (const Handle(Standard_Transient)& obj, const Handle(Transfer_FinderProcess)& FP, const Handle(Interface_InterfaceModel)& model, const Standard_Integer modetrans = 0) const;
161   
162   //! Tells if a shape is valid for a transfer to a model
163   //! Asks the ActorWrite (through a ShapeMapper)
164   Standard_EXPORT virtual Standard_Boolean RecognizeWriteShape (const TopoDS_Shape& shape, const Standard_Integer modetrans = 0) const;
165   
166   //! Takes one Shape and transfers it to an
167   //! InterfaceModel (already created, e.g. by NewModel)
168   //! Default uses ActorWrite; can be redefined as necessary
169   //! Returned value is a status, as follows :
170   //! Done  OK ,  Void : No Result ,  Fail : Fail (e.g. exception)
171   //! Error : bad conditions , bad model or null model
172   Standard_EXPORT virtual IFSelect_ReturnStatus TransferWriteShape (const TopoDS_Shape& shape, const Handle(Transfer_FinderProcess)& FP, const Handle(Interface_InterfaceModel)& model, const Standard_Integer modetrans = 0) const;
173   
174   //! Records a Session Item, to be added for customisation of the Work Session.
175   //! It must have a specific name.
176   //! <setapplied> is used if <item> is a GeneralModifier, to decide
177   //! If set to true, <item> will be applied to the hook list "send".
178   //! Else, it is not applied to any hook list.
179   //! Remark : this method is to be called at Create time,
180   //! the recorded items will be used by Customise
181   //! Warning : if <name> conflicts, the last recorded item is kept
182   Standard_EXPORT void AddSessionItem (const Handle(Standard_Transient)& theItem, const Standard_CString theName, const Standard_Boolean toApply = Standard_False);
183   
184   //! Returns an item given its name to record in a Session
185   //! If <name> is unknown, returns a Null Handle
186   Standard_EXPORT Handle(Standard_Transient) SessionItem (const Standard_CString theName) const;
187   
188   //! Customises a WorkSession, by adding to it the recorded items (by AddSessionItem)
189   Standard_EXPORT virtual void Customise (Handle(XSControl_WorkSession)& WS);
190   
191   const NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)> & AdaptorSession() const
192   { return myAdaptorSession; }
193
194   DEFINE_STANDARD_RTTIEXT(XSControl_Controller,Standard_Transient)
195
196  protected:
197   
198   //! Initializing with names
199   //! <theLongName>  is for the complete, official, long  name
200   //! <theShortName> is for the short name used for resources
201   Standard_EXPORT XSControl_Controller(const Standard_CString theLongName, const Standard_CString theShortName);
202
203   //! Records the name of a Static to be traced for a given use
204   Standard_EXPORT void TraceStatic (const Standard_CString theName, const Standard_Integer theUse);
205
206   TCollection_AsciiString myShortName;
207   TCollection_AsciiString myLongName;
208   Handle(IFSelect_WorkLibrary) myAdaptorLibrary;
209   Handle(Interface_Protocol) myAdaptorProtocol;
210   //szv:Handle(IFSelect_Signature) mySignType;
211   Handle(Transfer_ActorOfTransientProcess) myAdaptorRead;
212   Handle(Transfer_ActorOfFinderProcess) myAdaptorWrite;
213   NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)> myAdaptorSession;
214
215  private:
216
217   TColStd_SequenceOfTransient myAdaptorApplied;
218   NCollection_Vector<Handle(Standard_Transient)> myParams;
219   NCollection_Vector<Standard_Integer> myParamUses;
220   Handle(Interface_HArray1OfHAsciiString) myModeWriteShapeN;
221 };
222
223 #endif // _XSControl_Controller_HeaderFile