#pragma once #include #include #include // OTK headers #include #include #include #include #include #include #include #include #include #include #include #include #include class ComponentChildrenManager { public: // Request data structure struct ComponentChildrenRequest { std::string component_path; // Required: component path like "Assembly.asm/SubAsm.asm/Part.prt" int component_id = -1; // Optional: Creo Feature ID for additional validation (-1 means not specified) }; // Child component info structure struct ChildComponentInfo { int id; // Creo Feature ID std::string filename; // Component filename (e.g., "part.prt") std::string name; std::string type; // "part", "assembly" int level; std::string path; std::string full_path; std::string file_size; bool is_visible; std::string model_type; // "MDL_PART", "MDL_ASSEMBLY" int children_count; }; // Response data structure struct ComponentChildrenResult { bool success = false; std::string message; int parent_component_id = -1; // Creo Feature ID std::string parent_component_filename; // Component filename std::string parent_component_path; int children_count = 0; std::vector children; std::string error_message; }; private: // Session info structure struct SessionInfo { pfcSession_ptr session; bool is_valid = false; }; // Path parsing structure struct ParsedPath { std::vector path_segments; std::string target_component; bool is_valid = false; }; // Component match result struct ComponentMatch { pfcFeature_ptr feature; pfcComponentFeat_ptr component_feature; wfcWAssembly_ptr owner_assembly; std::string actual_path; bool found = false; }; private: // Helper methods SessionInfo GetSessionInfo(); ParsedPath ParseComponentPath(const std::string& full_path); bool FindComponentByPath(wfcWAssembly_ptr assembly, const ParsedPath& target_path, ComponentMatch& match); bool RecursiveSearchComponent(wfcWAssembly_ptr currentAssembly, const ParsedPath& target_path, const std::string& pathSoFar, int currentLevel, ComponentMatch& match); ChildComponentInfo CreateChildComponentFromFeature(pfcComponentFeat_ptr compFeat, int level, const std::string& parentPath); pfcModel_ptr LoadComponentModel(pfcComponentFeat_ptr compFeat); std::string GetModelFileSize(pfcModel_ptr model); // String utility methods std::string XStringToString(const xstring& xstr); xstring StringToXString(const std::string& str); bool CaseInsensitiveCompare(const std::string& str1, const std::string& str2); public: // Main interface method ComponentChildrenResult GetComponentFirstLevelChildren(const ComponentChildrenRequest& request); // Singleton pattern static ComponentChildrenManager& Instance() { static ComponentChildrenManager instance; return instance; } private: // Private constructor for singleton ComponentChildrenManager() = default; ComponentChildrenManager(const ComponentChildrenManager&) = delete; ComponentChildrenManager& operator=(const ComponentChildrenManager&) = delete; };