// 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 "Standard.hxx" #include "Standard_Type.hxx" #include "TCollection_AsciiString.hxx" #include "Interface_CheckIterator.hxx" #include "Standard_Transient.hxx" #include "NCollection_IndexedDataMap.hxx" #include "NCollection_DynamicArray.hxx" #include "NCollection_DataMap.hxx" #include "Standard_CString.hxx" #include "IFSelect_ReturnStatus.hxx" #include "Standard_Integer.hxx" #include "NCollection_Sequence.hxx" #include "NCollection_HSequence.hxx" #include "TCollection_HAsciiString.hxx" #include "IFSelect_RemainMode.hxx" #include "IFSelect_PrintCount.hxx" class IFSelect_ShareOut; class IFSelect_WorkLibrary; class Interface_Protocol; class Interface_InterfaceModel; class Interface_HGraph; class Interface_GTool; class IFSelect_ModelCopier; class IFSelect_Signature; class TCollection_HAsciiString; class Interface_Graph; 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; //! 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 bool toHandle); //! Returns the Error Handler status bool ErrorHandle() const { return theerrhand; } //! Returns the ShareOut defined at creation time const occ::handle& 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 occ::handle& shareout); //! Set value of mode responsible for presence 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 applications) void SetModeStat(const bool theMode) { themodelstat = theMode; } //! Return value of mode defining of filling selection during loading bool GetModeStat() const { return themodelstat; } //! Sets a WorkLibrary, which will be used to Read and Write Files void SetLibrary(const occ::handle& theLib) { thelibrary = theLib; } //! Returns the WorkLibrary. Null Handle if not yet set //! should be C++ : return const & const occ::handle& 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 occ::handle& protocol); //! Returns the Protocol. Null Handle if not yet set //! should be C++ : return const & const occ::handle& 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 occ::handle& signtype); //! Returns the current SignType Standard_EXPORT occ::handle SignType() const; //! Returns True is a Model has been set bool 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 occ::handle& model, const bool clearpointed = true); //! Returns the Model of the Work Session (Null Handle if none) //! should be C++ : return const & const occ::handle& 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 char* const theFileName) { theloaded = theFileName; } //! Returns the filename used to load current model //! empty if unknown const char* 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 char* const filename); //! Reads a file from stream 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 ReadStream(const char* const theName, std::istream& theIStream); //! Returns the count of Entities stored in the Model, or 0 Standard_EXPORT int NbStartingEntities() const; //! Returns an Entity stored in the Model of the WorkSession //! (Null Handle is no Model or num out of range) Standard_EXPORT occ::handle StartingEntity(const int num) const; //! Returns the Number of an Entity in the Model //! (0 if no Model set or not in the Model) Standard_EXPORT int StartingNumber(const occ::handle& 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 int NumberFromLabel(const char* const val, const int 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 occ::handle EntityLabel( const occ::handle& 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 occ::handle EntityName( const occ::handle& 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 int CategoryNumber(const occ::handle& 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 const char* CategoryName(const occ::handle& 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 const char* ValidityName(const occ::handle& 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 int 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 bool ComputeGraph(const bool enforce = false); //! Returns the Computed Graph as HGraph (Null Handle if not set) Standard_EXPORT occ::handle 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 occ::handle>> Shareds( const occ::handle& ent); //! Returns the list of entities sharing (can be empty) //! Returns a null Handle if is unknown Standard_EXPORT occ::handle>> Sharings( const occ::handle& 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 bool IsLoaded() const; //! Computes the CheckList for the Model currently loaded //! It can then be used for displays, queries ... //! 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 bool ComputeCheck(const bool enforce = 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 bool complete = 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 occ::handle& ent, const bool complete = 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 int MaxIdent() const; //! Returns an Item, given its Ident. Returns a Null Handle if //! no Item corresponds to this Ident. Standard_EXPORT occ::handle Item(const int id) const; //! Returns the Ident attached to an Item in the WorkSession, or //! Zero if it is unknown Standard_EXPORT int ItemIdent(const occ::handle& 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 occ::handle NamedItem(const char* const name) const; //! Same as above, but is given through a Handle //! Especially useful with methods SelectionNames, etc... Standard_EXPORT occ::handle NamedItem( const occ::handle& name) const; //! Returns the Ident attached to a Name, 0 if name not recorded Standard_EXPORT int NameIdent(const char* const name) const; //! Returns True if an Item of the WorkSession has an attached Name Standard_EXPORT bool HasName(const occ::handle& 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 occ::handle Name( const occ::handle& 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 int AddItem(const occ::handle& item, const bool active = 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 int AddNamedItem(const char* const name, const occ::handle& item, const bool active = 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 bool SetActive(const occ::handle& item, const bool 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 bool RemoveNamedItem(const char* const name); //! Removes a Name without removing the Item //! Returns True if Done, False else (Name not recorded) Standard_EXPORT bool RemoveName(const char* const 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 bool RemoveItem(const occ::handle& 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 occ::handle ItemLabel(const int 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 occ::handle> ItemIdents( const occ::handle& 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 occ::handle>> ItemNames(const occ::handle& type) const; //! Fills a Sequence with the NAMES of the control items, of which //! the label matches