// Created on: 1992-12-15 // Created by: Christian CAILLET // Copyright (c) 1992-1999 Matra Datavision // Copyright (c) 1999-2014 OPEN CASCADE SAS // // This file is part of Open CASCADE Technology software library. // // This library is free software; you can redistribute it and/or modify it under // the terms of the GNU Lesser General Public License version 2.1 as published // by the Free Software Foundation, with special exception defined in the file // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT // distribution for complete text of the license and disclaimer of any warranty. // // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. #ifndef _IFSelect_WorkSession_HeaderFile #define _IFSelect_WorkSession_HeaderFile #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include class IFSelect_ShareOut; class IFSelect_WorkLibrary; class Interface_Protocol; class Interface_InterfaceModel; class Interface_HGraph; class Interface_GTool; class IFSelect_ModelCopier; class Standard_DomainError; class IFSelect_Signature; class TCollection_HAsciiString; class Interface_Graph; class Interface_CheckIterator; class IFSelect_IntParam; class IFSelect_Selection; class Interface_EntityIterator; class IFSelect_SelectionIterator; class IFSelect_SignCounter; class IFSelect_Dispatch; class IFSelect_GeneralModifier; class IFSelect_Modifier; class IFSelect_Transformer; class IFSelect_PacketList; class IFSelect_SignatureList; class IFSelect_WorkSession; DEFINE_STANDARD_HANDLE(IFSelect_WorkSession, Standard_Transient) //! This class can be used to simply manage a process such as //! splitting a file, extracting a set of Entities ... //! It allows to manage different types of Variables : Integer or //! Text Parameters, Selections, Dispatches, in addition to a //! ShareOut. To each of these variables, a unique Integer //! Identifier is attached. A Name can be attached too as desired. class IFSelect_WorkSession : public Standard_Transient { public: //! Creates a Work Session //! It provides default, empty ShareOut and ModelCopier, which can //! be replaced (if required, should be done just after creation). Standard_EXPORT IFSelect_WorkSession(); //! Changes the Error Handler status (by default, it is not set) Standard_EXPORT void SetErrorHandle (const Standard_Boolean toHandle); //! Returns the Error Handler status Standard_Boolean ErrorHandle() const { return theerrhand; } //! Returns the ShareOut defined at creation time const Handle(IFSelect_ShareOut) & ShareOut() const { return theshareout; } //! Sets a new ShareOut. Fills Items which its content //! Warning : data from the former ShareOut are lost Standard_EXPORT void SetShareOut (const Handle(IFSelect_ShareOut)& shareout); //! Set value of mode responsible for precence of selections after loading //! If mode set to true that different selections will be accessible after loading //! else selections will be not accessible after loading( for economy memory in applicatios) void SetModeStat (const Standard_Boolean theMode) { themodelstat = theMode; } //! Return value of mode defining of filling selection during loading Standard_Boolean GetModeStat() const { return themodelstat; } //! Sets a WorkLibrary, which will be used to Read and Write Files void SetLibrary (const Handle(IFSelect_WorkLibrary) &theLib) { thelibrary = theLib; } //! Returns the WorkLibrary. Null Handle if not yet set //! should be C++ : return const & const Handle(IFSelect_WorkLibrary) & WorkLibrary() const { return thelibrary; } //! Sets a Protocol, which will be used to determine Graphs, to //! Read and to Write Files Standard_EXPORT void SetProtocol (const Handle(Interface_Protocol)& protocol); //! Returns the Protocol. Null Handle if not yet set //! should be C++ : return const & const Handle(Interface_Protocol) & Protocol() const { return theprotocol; } //! Sets a specific Signature to be the SignType, i.e. the //! Signature which will determine TypeName from the Model //! (basic function). It is recorded in the GTool //! This Signature is also set as "xst-sign-type" (reserved name) Standard_EXPORT void SetSignType (const Handle(IFSelect_Signature)& signtype); //! Returns the current SignType Standard_EXPORT Handle(IFSelect_Signature) SignType() const; //! Returns True is a Model has been set Standard_Boolean HasModel() const { return (!myModel.IsNull()); } //! Sets a Model as input : this will be the Model from which the //! ShareOut will work //! if is True (default) all SelectPointed items //! are cleared, else they must be managed by the caller //! Remark : SetModel clears the Graph, recomputes it if a //! Protocol is set and if the Model is not empty, of course Standard_EXPORT void SetModel (const Handle(Interface_InterfaceModel)& model, const Standard_Boolean clearpointed = Standard_True); //! Returns the Model of the Work Session (Null Handle if none) //! should be C++ : return const & const Handle(Interface_InterfaceModel) & Model () const { return myModel; } //! Stores the filename used for read for setting the model //! It is cleared by SetModel and ClearData(1) void SetLoadedFile (const Standard_CString theFileName) { theloaded = theFileName; } //! Returns the filename used to load current model //! empty if unknown Standard_CString LoadedFile() const { return theloaded.ToCString(); } //! Reads a file with the WorkLibrary (sets Model and LoadedFile) //! Returns a integer status which can be : //! RetDone if OK, RetVoid if no Protocol not defined, //! RetError for file not found, RetFail if fail during read Standard_EXPORT IFSelect_ReturnStatus ReadFile (const Standard_CString filename); //! Returns the count of Entities stored in the Model, or 0 Standard_EXPORT Standard_Integer NbStartingEntities() const; //! Returns an Entity stored in the Model of the WorkSession //! (Null Handle is no Model or num out of range) Standard_EXPORT Handle(Standard_Transient) StartingEntity (const Standard_Integer num) const; //! Returns the Number of an Entity in the Model //! (0 if no Model set or not in the Model) Standard_EXPORT Standard_Integer StartingNumber (const Handle(Standard_Transient)& ent) const; //! From a given label in Model, returns the corresponding number //! Starts from first entity by Default, may start after a given //! number : this number may be given negative, its absolute value //! is then considered. Hence a loop on NumberFromLabel may be //! programmed (stop test is : returned value positive or null) //! //! Returns 0 if not found, < 0 if more than one found (first //! found in negative). //! If just gives an integer value, returns it Standard_EXPORT Standard_Integer NumberFromLabel (const Standard_CString val, const Standard_Integer afternum = 0) const; //! Returns the label for , as the Model does //! If is not in the Model or if no Model is loaded, a Null //! Handle is returned Standard_EXPORT Handle(TCollection_HAsciiString) EntityLabel (const Handle(Standard_Transient)& ent) const; //! Returns the Name of an Entity //! This Name is computed by the general service Name //! Returns a Null Handle if fails Standard_EXPORT Handle(TCollection_HAsciiString) EntityName (const Handle(Standard_Transient)& ent) const; //! Returns the Category Number determined for an entity //! it is computed by the class Category //! An unknown entity (number 0) gives a value -1 Standard_EXPORT Standard_Integer CategoryNumber (const Handle(Standard_Transient)& ent) const; //! Returns the Category Name determined for an entity //! it is computed by the class Category //! Remark : an unknown entity gives an empty string Standard_EXPORT Standard_CString CategoryName (const Handle(Standard_Transient)& ent) const; //! Returns the Validity Name determined for an entity //! it is computed by the class SignValidity //! Remark : an unknown entity gives an empty string Standard_EXPORT Standard_CString ValidityName (const Handle(Standard_Transient)& ent) const; //! Clears recorded data (not the items) according mode : //! 1 : all Data : Model, Graph, CheckList, + ClearData 4 //! 2 : Graph and CheckList (they will then be recomputed later) //! 3 : CheckList (it will be recomputed by ComputeCheck) //! 4 : just content of SelectPointed and Counters //! Plus 0 : does nothing but called by SetModel //! ClearData is virtual, hence it can be redefined to clear //! other data of a specialised Work Session Standard_EXPORT virtual void ClearData (const Standard_Integer mode); //! Computes the Graph used for Selections, Displays ... //! If a HGraph is already set, with same model as given by method //! Model, does nothing. Else, computes a new Graph. //! If is given True, computes a new Graph anyway. //! Remark that a call to ClearGraph will cause ComputeGraph to //! really compute a new Graph //! Returns True if Graph is OK, False else (i.e. if no Protocol //! is set, or if Model is absent or empty). Standard_EXPORT Standard_Boolean ComputeGraph (const Standard_Boolean enforce = Standard_False); //! Returns the Computed Graph as HGraph (Null Handle if not set) Standard_EXPORT Handle(Interface_HGraph) HGraph(); //! Returns the Computed Graph, for Read only Standard_EXPORT const Interface_Graph& Graph(); //! Returns the list of entities shared by (can be empty) //! Returns a null Handle if is unknown Standard_EXPORT Handle(TColStd_HSequenceOfTransient) Shareds (const Handle(Standard_Transient)& ent); //! Returns the list of entities sharing (can be empty) //! Returns a null Handle if is unknown Standard_EXPORT Handle(TColStd_HSequenceOfTransient) Sharings (const Handle(Standard_Transient)& ent); //! Returns True if a Model is defined and really loaded (not //! empty), a Protocol is set and a Graph has been computed. //! In this case, the WorkSession can start to work Standard_EXPORT Standard_Boolean IsLoaded() const; //! Computes the CheckList for the Model currently loaded //! It can then be used for displays, querries ... //! Returns True if OK, False else (i.e. no Protocol set, or Model //! absent). If is False, works only if not already done //! or if a new Model has been loaded from last call. //! Remark : computation is enforced by every call to //! SetModel or RunTransformer Standard_EXPORT Standard_Boolean ComputeCheck (const Standard_Boolean enforce = Standard_False); //! Returns the Check List for the Model currently loaded : //! = True : complete (syntactic & semantic messages), //! computed if not yet done //! = False : only syntactic (check file form) Standard_EXPORT Interface_CheckIterator ModelCheckList (const Standard_Boolean complete = Standard_True); //! Returns a Check for a single entity, under the form of a //! CheckIterator (this gives only one form for the user) //! if is Null or equates the current Model, it gives the //! Global Check, else the Check for the given entity //! as for ModelCheckList Standard_EXPORT Interface_CheckIterator CheckOne (const Handle(Standard_Transient)& ent, const Standard_Boolean complete = Standard_True); //! Returns the Check List produced by the last execution of //! either : EvaluateFile(for Split), SendSplit, SendAll, //! SendSelected, RunTransformer-RunModifier //! Cleared by SetModel or ClearData(1) //! The field is protected, hence a specialized WorkSession may //! fill it Interface_CheckIterator LastRunCheckList() const { return thecheckrun; } //! Returns the Maximum Value for an Item Identifier. It can be //! greater to the count of known Items, because some can have //! been removed Standard_EXPORT Standard_Integer MaxIdent() const; //! Returns an Item, given its Ident. Returns a Null Handle if //! no Item corresponds to this Ident. Standard_EXPORT Handle(Standard_Transient) Item (const Standard_Integer id) const; //! Returns the Ident attached to an Item in the WorkSession, or //! Zero if it is unknown Standard_EXPORT Standard_Integer ItemIdent (const Handle(Standard_Transient)& item) const; //! Returns the Item which corresponds to a Variable, given its //! Name (whatever the type of this Item). //! Returns a Null Handle if this Name is not recorded Standard_EXPORT Handle(Standard_Transient) NamedItem (const Standard_CString name) const; //! Same as above, but is given through a Handle //! Especially Usefull with methods SelectionNames, etc... Standard_EXPORT Handle(Standard_Transient) NamedItem (const Handle(TCollection_HAsciiString)& name) const; //! Returns the Ident attached to a Name, 0 if name not recorded Standard_EXPORT Standard_Integer NameIdent (const Standard_CString name) const; //! Returns True if an Item of the WorkSession has an attached Name Standard_EXPORT Standard_Boolean HasName (const Handle(Standard_Transient)& item) const; //! Returns the Name attached to an Item as a Variable of this //! WorkSession. If is Null or not recorded, returns an //! empty string. Standard_EXPORT Handle(TCollection_HAsciiString) Name (const Handle(Standard_Transient)& item) const; //! Adds an Item and returns its attached Ident. Does nothing //! if is already recorded (and returns its attached Ident) //! if True commands call to SetActive (see below) //! Remark : the determined Ident is used if is a Dispatch, //! to fill the ShareOut Standard_EXPORT Standard_Integer AddItem (const Handle(Standard_Transient)& item, const Standard_Boolean active = Standard_True); //! Adds an Item with an attached Name. If the Name is already //! known in the WorkSession, the older item losts it //! Returns Ident if Done, 0 else, i.e. if is null //! If is empty, works as AddItem (i.e. with no name) //! If is already known but with no attached Name, this //! method tries to attached a Name to it //! if True commands call to SetActive (see below) Standard_EXPORT Standard_Integer AddNamedItem (const Standard_CString name, const Handle(Standard_Transient)& item, const Standard_Boolean active = Standard_True); //! Following the type of : //! - Dispatch : Adds or Removes it in the ShareOut & FileNaming //! - GeneralModifier : Adds or Removes it for final sending //! (i.e. in the ModelCopier) //! Returns True if it did something, False else (state unchanged) Standard_EXPORT Standard_Boolean SetActive (const Handle(Standard_Transient)& item, const Standard_Boolean mode); //! Removes an Item from the Session, given its Name //! Returns True if Done, False else (Name not recorded) //! (Applies only on Item which are Named) Standard_EXPORT Standard_Boolean RemoveNamedItem (const Standard_CString name); //! Removes a Name without removing the Item //! Returns True if Done, False else (Name not recorded) Standard_EXPORT Standard_Boolean RemoveName (const Standard_CString name); //! Removes an Item given its Ident. Returns False if is //! attached to no Item in the WorkSession. For a Named Item, //! also removes its Name. Standard_EXPORT Standard_Boolean RemoveItem (const Handle(Standard_Transient)& item); //! Clears all the recorded Items : Selections, Dispatches, //! Modifiers, and Strings & IntParams, with their Idents & Names. //! Remark that if a Model has been loaded, it is not cleared. Standard_EXPORT void ClearItems(); //! Returns a Label which illustrates the content of an Item, //! given its Ident. This Label is : //! - for a Text Parameter, "Text:" //! - for an Integer Parameter, "Integer:" //! - for a Selection, a Dispatch or a Modifier, its Label //! (see these classes) //! - for any other kind of Variable, its cdl type Standard_EXPORT Handle(TCollection_HAsciiString) ItemLabel (const Standard_Integer id) const; //! Fills a Sequence with the List of Idents attached to the Items //! of which Type complies with (IsKind) (alphabetic order) //! Remark : = TYPE(Standard_Transient) gives all the //! Idents which are suitable in the WorkSession Standard_EXPORT Handle(TColStd_HSequenceOfInteger) ItemIdents (const Handle(Standard_Type)& type) const; //! Fills a Sequence with the list of the Names attached to Items //! of which Type complies with (IsKind) (alphabetic order) //! Remark : = TYPE(Standard_Transient) gives all the Names Standard_EXPORT Handle(TColStd_HSequenceOfHAsciiString) ItemNames (const Handle(Standard_Type)& type) const; //! Fills a Sequence with the NAMES of the control items, of which //! the label matches