CreoOtkPluging/ComponentChildrenManager.h
sladro 8fd63500f2 feat: implement component children API with Creo Feature ID support
- Add ComponentChildrenManager class for retrieving first-level child components
- Support path-based component lookup with intelligent top-level assembly handling
- Return Creo Feature IDs instead of filenames for precise component identification
- Add comprehensive path resolution logic for nested assemblies
- Implement new API endpoint /api/creo/component/children

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-21 12:42:57 +08:00

119 lines
3.9 KiB
C++

#pragma once
#include <string>
#include <vector>
#include <map>
// OTK headers
#include <pfcGlobal.h>
#include <pfcSession.h>
#include <wfcSession.h>
#include <wfcGlobal.h>
#include <pfcModel.h>
#include <pfcExceptions.h>
#include <pfcFeature.h>
#include <pfcComponentFeat.h>
#include <pfcFeature_s.h>
#include <pfcSolid.h>
#include <wfcSolid.h>
#include <wfcAssembly.h>
#include <stdcols.h>
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<ChildComponentInfo> 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<std::string> 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;
};