0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / XSControl / XSControl_WorkSession.hxx
1 // Created on: 1995-06-01
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_WorkSession_HeaderFile
18 #define _XSControl_WorkSession_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
22
23 #include <IFSelect_WorkSession.hxx>
24 #include <IFSelect_ReturnStatus.hxx>
25 #include <XSControl_TransferWriter.hxx>
26 class XSControl_Controller;
27 class XSControl_TransferReader;
28 class XSControl_Vars;
29 class Message_Messenger;
30 class Transfer_TransientProcess;
31 class Standard_Transient;
32 class Interface_InterfaceModel;
33 class Transfer_FinderProcess;
34 class TopoDS_Shape;
35 class Interface_CheckIterator;
36
37
38 class XSControl_WorkSession;
39 DEFINE_STANDARD_HANDLE(XSControl_WorkSession, IFSelect_WorkSession)
40
41 //! This WorkSession completes the basic one, by adding :
42 //! - use of Controller, with norm selection...
43 //! - management of transfers (both ways) with auxiliary classes
44 //! TransferReader and TransferWriter
45 //! -> these transfers may work with a Context List : its items
46 //! are given by the user, according to the transfer to be
47 //! i.e. it is interpreted by the Actors
48 //! Each item is accessed by a Name
49 class XSControl_WorkSession : public IFSelect_WorkSession
50 {
51  public:
52   
53   Standard_EXPORT XSControl_WorkSession();
54   
55   ~XSControl_WorkSession()
56   { ClearBinders(); }
57
58   //! In addition to basic ClearData, clears Transfer and Management
59   //! for interactive use, for mode = 0,1,2 and over 4
60   //! Plus : mode = 5 to clear Transfers (both ways) only
61   //! mode = 6 to clear enforced results
62   //! mode = 7 to clear transfers, results
63   Standard_EXPORT virtual void ClearData (const Standard_Integer theMode) Standard_OVERRIDE;
64   
65   //! Selects a Norm defined by its name.
66   //! A Norm is described and handled by a Controller
67   //! Returns True if done, False if <normname> is unknown
68   //!
69   //! The current Profile for this Norm is taken.
70   Standard_EXPORT Standard_Boolean SelectNorm (const Standard_CString theNormName);
71   
72   //! Selects a Norm defined by its Controller itself
73   Standard_EXPORT void SetController (const Handle(XSControl_Controller)& theCtl);
74   
75   //! Returns the name of the last Selected Norm. If none is
76   //! defined, returns an empty string
77   //! By default, returns the complete name of the norm
78   //! If <rsc> is True, returns the short name used for resource
79   Standard_EXPORT Standard_CString SelectedNorm (const Standard_Boolean theRsc = Standard_False) const;
80   
81   //! Returns the norm controller itself
82   const Handle(XSControl_Controller) & NormAdaptor() const
83   { return myController; }
84   
85   //! Returns the current Context List, Null if not defined
86   //! The Context is given to the TransientProcess for TransferRead
87   const NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)> & Context() const
88   { return myContext; }
89   
90   //! Sets the current Context List, as a whole
91   //! Sets it to the TransferReader
92   Standard_EXPORT void SetAllContext (const NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)>& theContext);
93   
94   //! Clears the whole current Context (nullifies it)
95   Standard_EXPORT void ClearContext();
96   
97   //! Prints the transfer status of a transferred item, as beeing
98   //! the Mapped n0 <num>, from MapWriter if <wri> is True, or
99   //! from MapReader if <wri> is False
100   //! Returns True when done, False else (i.e. num out of range)
101   Standard_EXPORT Standard_Boolean PrintTransferStatus (const Standard_Integer theNum, const Standard_Boolean theWri, Standard_OStream& theS) const;
102   
103   //! Sets a Transfer Reader, by internal ways, according mode :
104   //! 0 recreates it clear,  1 clears it (does not recreate)
105   //! 2 aligns Roots of TransientProcess from final Results
106   //! 3 aligns final Results from Roots of TransientProcess
107   //! 4 begins a new transfer (by BeginTransfer)
108   //! 5 recreates TransferReader then begins a new transfer
109   Standard_EXPORT void InitTransferReader (const Standard_Integer theMode);
110   
111   //! Sets a Transfer Reader, which manages transfers on reading
112   Standard_EXPORT void SetTransferReader (const Handle(XSControl_TransferReader)& theTR);
113   
114   //! Returns the Transfer Reader, Null if not set
115   const Handle(XSControl_TransferReader) & TransferReader () const
116   { return myTransferReader; }
117
118   //! Returns the TransientProcess(internal data for TransferReader)
119   Standard_EXPORT Handle(Transfer_TransientProcess) MapReader() const;
120
121   //! Changes the Map Reader, i.e. considers that the new one
122   //! defines the relevant read results (forgets the former ones)
123   //! Returns True when done, False in case of bad definition, i.e.
124   //! if Model from TP differs from that of Session
125   Standard_EXPORT Standard_Boolean SetMapReader (const Handle(Transfer_TransientProcess)& theTP);
126   
127   //! Returns the result attached to a starting entity
128   //! If <mode> = 0, returns Final Result
129   //! If <mode> = 1, considers Last Result
130   //! If <mode> = 2, considers Final, else if absent, Last
131   //! returns it as Transient, if result is not transient returns
132   //! the Binder
133   //! <mode> = 10,11,12 idem but returns the Binder itself
134   //! (if it is not, e.g. Shape, returns the Binder)
135   //! <mode> = 20, returns the ResultFromModel
136   Standard_EXPORT Handle(Standard_Transient) Result (const Handle(Standard_Transient)& theEnt, const Standard_Integer theMode) const;
137   
138   //! Commands the transfer of, either one entity, or a list
139   //! I.E. calls the TransferReader after having analysed <ents>
140   //! It is cumulated from the last BeginTransfer
141   //! <ents> is processed by GiveList, hence :
142   //! - <ents> a Selection : its SelectionResult
143   //! - <ents> a HSequenceOfTransient : this list
144   //! - <ents> the Model : in this specific case, all the roots,
145   //! with no cumulation of former transfers (TransferReadRoots)
146   Standard_EXPORT Standard_Integer TransferReadOne (const Handle(Standard_Transient)& theEnts);
147   
148   //! Commands the transfer of all the root entities of the model
149   //! i.e. calls TransferRoot from the TransferReader with the Graph
150   //! No cumulation with former calls to TransferReadOne
151   Standard_EXPORT Standard_Integer TransferReadRoots();
152   
153   //! produces and returns a new Model well conditionned
154   //! It is produced by the Norm Controller
155   //! It can be Null (if this function is not implemented)
156   Standard_EXPORT Handle(Interface_InterfaceModel) NewModel();
157   
158   //! Returns the Transfer Reader, Null if not set
159   const Handle(XSControl_TransferWriter) & TransferWriter() const
160   { return myTransferWriter; }
161   
162   //! Changes the Map Reader, i.e. considers that the new one
163   //! defines the relevant read results (forgets the former ones)
164   //! Returns True when done, False if <FP> is Null
165   Standard_Boolean SetMapWriter (const Handle(Transfer_FinderProcess)& theFP)
166   {
167     if (theFP.IsNull()) return Standard_False;
168     myTransferWriter->SetFinderProcess(theFP);
169     return Standard_True;
170   }
171   
172   //! Transfers a Shape from CasCade to a model of current norm,
173   //! according to the last call to SetModeWriteShape
174   //! Returns status :Done if OK, Fail if error during transfer,
175   //! Error if transfer badly initialised
176   Standard_EXPORT IFSelect_ReturnStatus TransferWriteShape (const TopoDS_Shape& theShape, const Standard_Boolean theCompGraph = Standard_True);
177   
178   //! Returns the check-list of last transfer (write)
179   //! It is recorded in the FinderProcess, but it must be bound with
180   //! resulting entities (in the resulting file model) rather than
181   //! with original objects (in fact, their mappers)
182   Standard_EXPORT Interface_CheckIterator TransferWriteCheckList() const;
183   
184   const Handle(XSControl_Vars) & Vars() const
185   { return myVars; }
186   
187   void SetVars (const Handle(XSControl_Vars)& theVars)
188   { myVars = theVars; }
189   
190   DEFINE_STANDARD_RTTIEXT(XSControl_WorkSession,IFSelect_WorkSession)
191
192  private:
193   
194   //! Clears binders
195   Standard_EXPORT void ClearBinders();
196
197   Handle(XSControl_Controller) myController;
198   Handle(XSControl_TransferReader) myTransferReader;
199   Handle(XSControl_TransferWriter) myTransferWriter;
200   NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)> myContext;
201   Handle(XSControl_Vars) myVars;
202 };
203
204 #endif // _XSControl_WorkSession_HeaderFile