Archicad 28 C++ API
Loading...
Searching...
No Matches
ACAPI::MEP::v1::DistributionSystemsGraph Class Referencefinal

A graph data structure to display MEP distribution systems data. More...

#include <MEPDistributionSystemsGraph.hpp>

Inheritance diagram for ACAPI::MEP::v1::DistributionSystemsGraph:
ACAPI::v1::Object

Public Member Functions

std::vector< DistributionSystemGetSystems () const
 
std::vector< UniqueIDGetElements () const
 
std::vector< UniqueIDGetPorts () const
 
Result< void > TraverseTree (const DistributionSystem &system, std::function< bool(const DistributionSystemsGraphTreeNode &)> traversalFunction) const
 Traverses a distribution system in the graph through a tree layout with a traversal function invoked for each generated node in the tree.
 
- Public Member Functions inherited from ACAPI::v1::Object
 Object (std::shared_ptr< Impl::ObjectImpl > impl)
 Constructs a new object.
 
const API_TokenGetToken () const
 Get the token for this object.
 

Friends

class ACAPI::Impl::ObjectCreator
 
Result< DistributionSystemsGraphCreateDistributionSystemsGraph ()
 Creates a DistributionSystemsGraph.
 

Additional Inherited Members

- Protected Member Functions inherited from ACAPI::v1::Object
 ~Object ()
 Default destructor.
 
- Protected Attributes inherited from ACAPI::v1::Object
std::shared_ptr< Impl::ObjectImplmImpl
 Impl object given by constructor.
 

Detailed Description

A graph data structure to display MEP distribution systems data.

A "distribution system" is defined as a connected set of elements sharing a common system category and MEP domain. (E.g. "hot water pipes" or "cold air ducts")

Since
Archicad 28
Example code snippets from Test / New MEP
TraverseTree
GSErrCode traversalError { NoError };
ACAPI::Result<void, ACAPI::Error> result = system.TraverseTree ([&] (const ACAPI::MEP::DistributionSystemsGraphTreeNode& node) -> bool {
const ACAPI::Result<Element> mepElement = Element::Get (node.GetElement ());
// If the element is invalid, continue traversal.
if (mepElement.IsErr ())
return true;
std::string connectedFrom;
if (node.GetPreviousElement ().has_value ())
connectedFrom = std::to_string (idToIndex[*node.GetPreviousElement ()]);
else
connectedFrom = "No connection";
std::string connectedTo;
if (node.GetNextElements ().size () == 0)
connectedTo = "No connections";
else {
for (const auto nextElement : node.GetNextElements ()) {
if (!connectedTo.empty ())
connectedTo += ", ";
connectedTo += std::to_string (idToIndex[nextElement]);
}
}
API_Element textElement = {};
textElement.header.type = API_TextID;
API_ElementMemo textMemo;
traversalError = ACAPI_Element_GetDefaults (&textElement, &textMemo);
if (traversalError != NoError)
return false;
textElement.text.size = 0.5;
textElement.text.loc.x = mepElement->GetAnchorPoint ().x;
textElement.text.loc.y = mepElement->GetAnchorPoint ().y;
textElement.text.multiStyle = false;
textMemo.textContent = new GS::UniString { GS::UniString::SPrintf ("%llu:\nConnectedFrom: %s\nConnectedTo: %s", idToIndex[node.GetElement ()], connectedFrom.c_str (), connectedTo.c_str ()) };
traversalError = ACAPI_Element_Create (&textElement, &textMemo);
if (traversalError == NoError)
traversalError = ACAPI_DisposeElemMemoHdls (&textMemo);
// Don't continue traversal if we've encountered an error
if (traversalError != NoError)
return false;
return true;
});
A structural helper class used when iterating through a DistributionSystem in the DistributionSystems...
Definition: MEPDistributionSystemsGraphTreeNode.hpp:43
std::optional< UniqueID > GetPreviousElement() const
std::vector< UniqueID > GetNextElements() const
static Result< Element > Get(const UniqueID &uniqueId)
Returns an Element.
Result is the standard return type of API functions.
Definition: Result.hpp:845
bool IsErr() const
Definition: Result.hpp:945
GSErrCode ACAPI_Element_GetDefaults(API_Element *element, API_ElementMemo *memo)
Retrieves the actual default settings for the element of type.
GSErrCode ACAPI_DisposeElemMemoHdls(API_ElementMemo *memo)
Frees the memory occupied by all of the allocated memo handles.
GSErrCode ACAPI_Element_Create(API_Element *element, API_ElementMemo *memo)
Places a new element into current database.
double x
Horizontal coordinate.
Definition: APIdefs_Base.h:87
double y
Vertical coordinate.
Definition: APIdefs_Base.h:93
API_ElemType type
The type of the element.
Definition: APIdefs_Elements.h:407
Describes the variable length additional data of elements.
Definition: APIdefs_Elements.h:17660
GS::UniString * textContent
Text content for textual elements.
Definition: APIdefs_Elements.h:17750
bool multiStyle
Multistyle text (input only).
Definition: APIdefs_Elements.h:9033
API_Coord loc
Coordinates of text anchor point.
Definition: APIdefs_Elements.h:9009
double size
Character height in mm.
Definition: APIdefs_Elements.h:8933
A union collecting all known element types.
Definition: APIdefs_Elements.h:17120
API_Elem_Head header
General element header.
Definition: APIdefs_Elements.h:17126
API_TextType text
Represents a text.
Definition: APIdefs_Elements.h:17219
GetElements
for (const auto elementId : distributionGraph.GetElements ())
idToIndex[elementId] = ++index;
std::vector< UniqueID > GetElements() const
GetSystems
for (const auto& system : distributionGraph.GetSystems ()) {
std::vector< DistributionSystem > GetSystems() const

Member Function Documentation

◆ GetElements()

std::vector< UniqueID > ACAPI::MEP::v1::DistributionSystemsGraph::GetElements ( ) const
Returns
Returns the unique IDs of all the elements collected by the graph structure
for (const auto elementId : distributionGraph.GetElements ())
idToIndex[elementId] = ++index;

◆ GetPorts()

std::vector< UniqueID > ACAPI::MEP::v1::DistributionSystemsGraph::GetPorts ( ) const
Returns
Returns the unique IDs of all the ports collected by the graph structure

◆ GetSystems()

std::vector< DistributionSystem > ACAPI::MEP::v1::DistributionSystemsGraph::GetSystems ( ) const
Returns
Returns the distribution systems collected by the graph structure
for (const auto& system : distributionGraph.GetSystems ()) {

◆ TraverseTree()

Result< void > ACAPI::MEP::v1::DistributionSystemsGraph::TraverseTree ( const DistributionSystem system,
std::function< bool(const DistributionSystemsGraphTreeNode &)>  traversalFunction 
) const

Traverses a distribution system in the graph through a tree layout with a traversal function invoked for each generated node in the tree.

Traversal is done in a depth first search (DFS) pattern starting with a root node defined by the system itself.

Parameters
systemThe desired distribution system to traverse
traversalFunctionA callable that will be invoked once per tree node. Return false in callable to exit traversal early.
Returns
Returns an Error if the distribution system could not be found or if traversal failed, otherwise nothing
GSErrCode traversalError { NoError };
ACAPI::Result<void, ACAPI::Error> result = system.TraverseTree ([&] (const ACAPI::MEP::DistributionSystemsGraphTreeNode& node) -> bool {
const ACAPI::Result<Element> mepElement = Element::Get (node.GetElement ());
// If the element is invalid, continue traversal.
if (mepElement.IsErr ())
return true;
std::string connectedFrom;
if (node.GetPreviousElement ().has_value ())
connectedFrom = std::to_string (idToIndex[*node.GetPreviousElement ()]);
else
connectedFrom = "No connection";
std::string connectedTo;
if (node.GetNextElements ().size () == 0)
connectedTo = "No connections";
else {
for (const auto nextElement : node.GetNextElements ()) {
if (!connectedTo.empty ())
connectedTo += ", ";
connectedTo += std::to_string (idToIndex[nextElement]);
}
}
API_Element textElement = {};
textElement.header.type = API_TextID;
API_ElementMemo textMemo;
traversalError = ACAPI_Element_GetDefaults (&textElement, &textMemo);
if (traversalError != NoError)
return false;
textElement.text.size = 0.5;
textElement.text.loc.x = mepElement->GetAnchorPoint ().x;
textElement.text.loc.y = mepElement->GetAnchorPoint ().y;
textElement.text.multiStyle = false;
textMemo.textContent = new GS::UniString { GS::UniString::SPrintf ("%llu:\nConnectedFrom: %s\nConnectedTo: %s", idToIndex[node.GetElement ()], connectedFrom.c_str (), connectedTo.c_str ()) };
traversalError = ACAPI_Element_Create (&textElement, &textMemo);
if (traversalError == NoError)
traversalError = ACAPI_DisposeElemMemoHdls (&textMemo);
// Don't continue traversal if we've encountered an error
if (traversalError != NoError)
return false;
return true;
});

Friends And Related Symbol Documentation

◆ CreateDistributionSystemsGraph

Result< DistributionSystemsGraph > CreateDistributionSystemsGraph ( )
friend

Creates a DistributionSystemsGraph.

Returns
If able, creates a new DistributionSystemsGraph, otherwise Error.
auto newGraph = ACAPI::MEP::CreateDistributionSystemsGraph ();
if (newGraph.IsErr ())
return APIERR_COMMANDFAILED;