+//================================================================================
+/*!
+ * \brief Returns the string of publishing commands. Take into account that
+ * references should be published prior to the objects refer to them.
+ */
+//================================================================================
+TCollection_AsciiString GetPublishCommands
+ (const int theTag,
+ const std::map< int, TCollection_AsciiString > &theEntryToCmdMap,
+ const TIntToListIntMap &theMapRefs,
+ std::set< int > &thePublished)
+{
+ TCollection_AsciiString aResult;
+
+ if (!thePublished.count(theTag)) {
+ // This object is not published yet.
+ std::map< int, TCollection_AsciiString >::const_iterator anIt =
+ theEntryToCmdMap.find(theTag);
+
+ if (anIt != theEntryToCmdMap.end()) {
+ // There is a pubish cmd.
+ TIntToListIntMap::const_iterator aRefIt = theMapRefs.find(theTag);
+
+ if (aRefIt != theMapRefs.end()) {
+ // Recursively publish all references.
+ std::list< int >::const_iterator aRefTagIt = aRefIt->second.begin();
+
+ for(; aRefTagIt != aRefIt->second.end(); ++aRefTagIt) {
+ const TCollection_AsciiString aRefCmd = GetPublishCommands
+ (*aRefTagIt, theEntryToCmdMap, theMapRefs, thePublished);
+
+ aResult += aRefCmd;
+ }
+ }
+
+ // Add the object command.
+ aResult += anIt->second;
+ }
+
+ thePublished.insert(theTag);
+ }
+
+ return aResult;
+}
+
+void Prettify(TCollection_AsciiString& theScript)
+{
+ TCollection_AsciiString output;
+ static std::list<TCollection_AsciiString> ToRemove;
+ if (ToRemove.empty()) {
+ ToRemove.push_back("geompy.SubShapeAllIDs");
+ ToRemove.push_back("geompy.SubShapeAllSortedCentresIDs");
+ ToRemove.push_back("geompy.SubShapeAllSortedIDs");
+ ToRemove.push_back("geompy.GetFreeFacesIDs");
+ ToRemove.push_back("geompy.GetShapesOnBoxIDs");
+ ToRemove.push_back("geompy.GetShapesOnShapeIDs");
+ ToRemove.push_back("geompy.GetShapesOnPlaneIDs");
+ ToRemove.push_back("geompy.GetShapesOnPlaneWithLocationIDs");
+ ToRemove.push_back("geompy.GetShapesOnCylinderIDs");
+ ToRemove.push_back("geompy.GetShapesOnCylinderWithLocationIDs");
+ ToRemove.push_back("geompy.GetShapesOnSphereIDs");
+ ToRemove.push_back("geompy.GetShapesOnQuadrangleIDs");
+ ToRemove.push_back("geompy.GetSameIDs");
+ }
+
+ int start = 1;
+ while (start <= theScript.Length()) {
+ int end = theScript.Location("\n", start, theScript.Length());
+ if (end == -1) end = theScript.Length();
+ TCollection_AsciiString line = theScript.SubString(start, end);
+ bool found = false;
+ for (std::list<TCollection_AsciiString>::const_iterator it = ToRemove.begin(); it != ToRemove.end() && !found; ++it)
+ found = line.Search( *it ) != -1;
+ if (!found)
+ output += line;
+ start = end + 1;
+ }
+ theScript = output;
+
+ //OK @@@@@@@@@@@@@@@@@@@@@@@@@@@
+}
+