+void Prettify(TCollection_AsciiString& theScript);
+
+// Helper functions
+namespace
+{
+ // Specifies a way to process a given function
+ enum FunctionProcessType { NOT_PROCESS, TO_PROCESS, UPDATE_DESCRIPTION };
+
+ // Starting string for an edge case where function was dumped from Python code
+ const Standard_CString funcFromPythonStartString = "from salome.geom.geomrepairadv";
+
+
+ //================================================================================
+ /*!
+ * \brief Checks if a description contents a function that was dumped from Python code
+ */
+ //================================================================================
+ bool IsFunctionSetFromPython(const TCollection_AsciiString& aDescr)
+ {
+ // TODO: make it more generic and not depended on geomrepairadv name
+ return aDescr.Search(funcFromPythonStartString) != -1;
+ }
+
+
+ //================================================================================
+ /*!
+ * \brief Removes from description the part before specific import statement
+ */
+ //================================================================================
+ void UpdateFuncFromPythonDescription(TCollection_AsciiString& aDescr)
+ {
+ const Standard_Integer startStringPos = aDescr.Search(funcFromPythonStartString);
+ MESSAGE("Description should start from pos: " << startStringPos);
+ if (startStringPos == -1)
+ {
+ MESSAGE("Can't find a string:\n" << funcFromPythonStartString << " \nin func description!");
+ return;
+ }
+
+ // Remove everything from the beginning till the starting point.
+ // Index starts from 1 not 0!
+ aDescr.Remove(1, startStringPos - 1);
+ MESSAGE("Updated func description: " << aDescr);
+ }
+
+
+ //================================================================================
+ /*!
+ * \brief Finds out how we should process a given function for Python dump
+ */
+ //================================================================================
+ FunctionProcessType GetFunctionProcessingType(const Handle(GEOM_Function)& theFunction, const TDF_LabelMap& theProcessed, const TCollection_AsciiString& aDescr)
+ {
+ MESSAGE("Start check function dependencies...");
+
+ TDF_LabelSequence aSeq;
+ theFunction->GetDependency(aSeq);
+ const Standard_Integer aLen = aSeq.Length();
+
+ for (Standard_Integer i = 1; i <= aLen; i++) {
+ TDF_Label aRefLabel = aSeq.Value(i);
+ Handle(TDF_Reference) aRef;
+ if (!aRefLabel.FindAttribute(TDF_Reference::GetID(), aRef)) {
+ MESSAGE("Can't find TDF_Reference::GetID() attribute. Do not process.");
+ return NOT_PROCESS;
+ }
+
+ if (aRef.IsNull() || aRef->Get().IsNull()) {
+ MESSAGE("Reference to attribute is null. Do not process.");
+ return NOT_PROCESS;
+ }
+
+ Handle(TDataStd_TreeNode) aT;
+ if (!TDataStd_TreeNode::Find(aRef->Get(), aT)) {
+ MESSAGE("Can't find a tree node. Do not process.");
+ return NOT_PROCESS;
+ }
+
+ TDF_Label aDepLabel = aT->Label();
+ Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(aDepLabel);
+ if (aFunction.IsNull()) {
+ MESSAGE("Function is null. Do not process." << aFunction->GetDescription());
+ return NOT_PROCESS;
+ }
+
+ if (!theProcessed.Contains(aDepLabel)) {
+ // Special case for function dumped from Python, because it's appended to
+ // description of other function that should be rejected early.
+ // TODO: it's not clear if we need to check every given function or
+ // checking on this level is enough. At this moment it's better to stay here
+ // for performance reason.
+ if (IsFunctionSetFromPython(aDescr)) {
+ MESSAGE("Function set from Python. Do process with updated description.");
+ return UPDATE_DESCRIPTION;
+ }
+
+ MESSAGE("The dependency label is not in processed list. Do not process.");
+ return NOT_PROCESS;
+ }
+ }
+
+ MESSAGE("OK. Do process the function.");
+ return TO_PROCESS;
+ }
+
+ //================================================================================
+ /*!
+ * \brief Adds function's object to ignored for Python dump output
+ */
+ //================================================================================
+ void AddFuncObjectToIgnored(const Handle(GEOM_Function)& theFunction, std::set<TCollection_AsciiString>& theIgnoreObjs)
+ {
+ TCollection_AsciiString anObjEntry;
+ TDF_Tool::Entry(theFunction->GetOwnerEntry(), anObjEntry);
+ theIgnoreObjs.insert(anObjEntry);
+ }
+
+}
+
+