Compare commits

...

6 Commits

Author SHA1 Message Date
David Kekesi e9d669c4dd do not merge - hack for exporting gridlines - each edge is a separate polyline 2024-10-31 18:15:08 +01:00
David Kekesi e4e31314d6 WIP 2024-10-31 13:09:35 +01:00
Ralph Wessel 82bd96de61 Updated Xcode project 2024-10-30 22:55:23 +00:00
Ralph Wessel 51ed951d7d Added Platform::openURL to open a URL cross-platform 2024-10-30 22:54:17 +00:00
Ralph Wessel cc6c884f47 Merge pull request #15 from specklesystems/david/wire-in-view-button
view button on modelcard works
2024-10-30 22:42:57 +00:00
David Kekesi 4afed92ba9 view button on modelcard works 2024-10-30 19:34:27 +01:00
12 changed files with 250 additions and 12 deletions
+2
View File
@@ -105,6 +105,7 @@
<ClCompile Include="Connector\Interface\Browser\Bridge\Base\GetSourceApplicationName.cpp" />
<ClCompile Include="Connector\Interface\Browser\Bridge\Base\GetSourceApplicationVersion.cpp" />
<ClCompile Include="Connector\Interface\Browser\Bridge\Base\HighlightModel.cpp" />
<ClCompile Include="Connector\Interface\Browser\Bridge\Base\OpenUrl.cpp" />
<ClCompile Include="Connector\Interface\Browser\Bridge\Base\RemoveModel.cpp" />
<ClCompile Include="Connector\Interface\Browser\Bridge\Base\UpdateModel.cpp" />
<ClCompile Include="Connector\Interface\Browser\Bridge\Config\Arg\ConnectorConfig.cpp" />
@@ -161,6 +162,7 @@
<ClInclude Include="Connector\Interface\Browser\Bridge\Base\GetSourceApplicationName.h" />
<ClInclude Include="Connector\Interface\Browser\Bridge\Base\GetSourceApplicationVersion.h" />
<ClInclude Include="Connector\Interface\Browser\Bridge\Base\HighlightModel.h" />
<ClInclude Include="Connector\Interface\Browser\Bridge\Base\OpenUrl.h" />
<ClInclude Include="Connector\Interface\Browser\Bridge\Base\RemoveModel.h" />
<ClInclude Include="Connector\Interface\Browser\Bridge\Base\UpdateModel.h" />
<ClInclude Include="Connector\Interface\Browser\Bridge\Config\Arg\ConnectorConfig.h" />
@@ -246,6 +246,9 @@
<ClCompile Include="Connector\Interface\Browser\Bridge\Base\HighlightModel.cpp">
<Filter>Connector\Interface\Browser\Bridge\Base</Filter>
</ClCompile>
<ClCompile Include="Connector\Interface\Browser\Bridge\Base\OpenUrl.cpp">
<Filter>Connector\Interface\Browser\Bridge\Base</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Connector\ConnectorResource.h">
@@ -417,5 +420,8 @@
<ClInclude Include="Connector\Interface\Browser\Bridge\Base\HighlightModel.h">
<Filter>Connector\Interface\Browser\Bridge\Base</Filter>
</ClInclude>
<ClInclude Include="Connector\Interface\Browser\Bridge\Base\OpenUrl.h">
<Filter>Connector\Interface\Browser\Bridge\Base</Filter>
</ClInclude>
</ItemGroup>
</Project>
@@ -23,6 +23,7 @@
/* Begin PBXBuildFile section */
210CC8832C80E6A300610F58 /* TriggerEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 210CC8812C80E6A300610F58 /* TriggerEvent.cpp */; };
21384BCD2CD2EE7400D4602B /* OpenUrl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21384BC92CD2EE7400D4602B /* OpenUrl.cpp */; };
213CC39C2B1101F500088049 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2151077C2AEDB9070022CD24 /* Cocoa.framework */; };
214B7A372C764BCD00D586C1 /* UpdateConfig.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21F69FBD2C7630B3008B6A06 /* UpdateConfig.cpp */; };
215F082A2C947F4400CD343B /* CardMover.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 215F08262C947F4400CD343B /* CardMover.cpp */; };
@@ -296,6 +297,8 @@
/* Begin PBXFileReference section */
210CC8812C80E6A300610F58 /* TriggerEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TriggerEvent.cpp; sourceTree = "<group>"; };
210CC8822C80E6A300610F58 /* TriggerEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TriggerEvent.h; sourceTree = "<group>"; };
21384BC92CD2EE7400D4602B /* OpenUrl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OpenUrl.cpp; sourceTree = "<group>"; };
21384BCC2CD2EE7400D4602B /* OpenUrl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OpenUrl.h; sourceTree = "<group>"; };
213CC3A52B1101F500088049 /* Speckle Connector.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Speckle Connector.bundle"; sourceTree = BUILT_PRODUCTS_DIR; };
2151077C2AEDB9070022CD24 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
215F08262C947F4400CD343B /* CardMover.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CardMover.cpp; sourceTree = "<group>"; };
@@ -1031,6 +1034,8 @@
21B67CAA2C77329800FD64FC /* GetSourceApplicationVersion.h */,
21A79EC52CCDA45C001754E4 /* HighlightModel.cpp */,
21A79EC82CCDA45C001754E4 /* HighlightModel.h */,
21384BC92CD2EE7400D4602B /* OpenUrl.cpp */,
21384BCC2CD2EE7400D4602B /* OpenUrl.h */,
21D0BDD52C935DAE0077E104 /* RemoveModel.cpp */,
21D0BDD62C935DAE0077E104 /* RemoveModel.h */,
21D0BDD22C935D1A0077E104 /* UpdateModel.cpp */,
@@ -1526,6 +1531,7 @@
21D0BDD72C935DAE0077E104 /* RemoveModel.cpp in Sources */,
21A890BC2CC15C540087E732 /* SelectionInfo.cpp in Sources */,
21AEF9EF2CAB5720000B8681 /* SendObject.cpp in Sources */,
21384BCD2CD2EE7400D4602B /* OpenUrl.cpp in Sources */,
21B67CDC2C78C88000FD64FC /* SayHi.cpp in Sources */,
215F082E2C94C5C000CD343B /* FilterMover.cpp in Sources */,
21F69F122C677BC0008B6A06 /* ConnectorMenu.cpp in Sources */,
@@ -8,6 +8,7 @@
#include "Connector/Interface/Browser/Bridge/Base/RemoveModel.h"
#include "Connector/Interface/Browser/Bridge/Base/UpdateModel.h"
#include "Connector/Interface/Browser/Bridge/Base/HighlightModel.h"
#include "Connector/Interface/Browser/Bridge/Base/OpenUrl.h"
#include "Speckle/Event/Type/ProjectEvent.h"
using namespace connector::interfac::browser::bridge;
@@ -26,6 +27,7 @@ BaseBridge::BaseBridge() : BrowserBridge{"baseBinding"} {
addMethod<RemoveModel>();
addMethod<UpdateModel>();
addMethod<HighlightModel>();
addMethod<OpenUrl>();
} //BaseBridge::BaseBridge
/*--------------------------------------------------------------------
@@ -0,0 +1,24 @@
#include "Connector/Interface/Browser/Bridge/Base/OpenUrl.h"
#include "Speckle/Environment/Platform.h"
using namespace connector::interfac::browser::bridge;
using namespace speckle::environment;
using namespace speckle::utility;
/*--------------------------------------------------------------------
Default constructor
--------------------------------------------------------------------*/
OpenUrl::OpenUrl() : BridgeMethod{"OpenUrl", [&](const SendArgs& args) {
run(args);
}} {}
/*--------------------------------------------------------------------
Opens an url
url: The URL to open
--------------------------------------------------------------------*/
void OpenUrl::run(const String& url) const {
platform()->openURL(url);
} //OpenUrl::run
@@ -0,0 +1,41 @@
#ifndef CONNECTOR_INTERFACE_BRIDGE_OPEN_URL
#define CONNECTOR_INTERFACE_BRIDGE_OPEN_URL
#include "Active/Serialise/CargoHold.h"
#include "Active/Serialise/Item/Wrapper/ValueWrap.h"
#include "Speckle/Interface/Browser/Bridge/BridgeMethod.h"
namespace connector::interfac::browser::bridge {
class ConnectorConfig;
///Argument parameter for a string
using StringHold = active::serialise::CargoHold<active::serialise::ValueWrap<speckle::utility::String>, speckle::utility::String>;
///Argument type for this method
using SendArgs = speckle::interfac::browser::bridge::JSArgType<StringHold>;
/*!
JS Function class to highlight elements from the selected model card in the open document
*/
class OpenUrl : public speckle::interfac::browser::bridge::BridgeMethod<SendArgs, void> {
public:
// MARK: - Constructors
/*!
Constructor
*/
OpenUrl();
// MARK: - Functions (const)
/*!
Opens an url
@param url The URL to open
*/
void run(const speckle::utility::String& url) const;
};
}
#endif //CONNECTOR_INTERFACE_BRIDGE_OPEN_URL
@@ -100,7 +100,7 @@ namespace connector::record {
///Finish proxies accumulated from meshes generated from the collection elements
FinishProxies m_finishProxies;
class FinishCache;
///Finishes cached from ModelerAPI materials
///Finishes cache
std::unique_ptr<FinishCache> m_finishes;
};
@@ -27,6 +27,22 @@ void Platform::writeToConsole(const active::utility::String& message) {
} //Platform::writeToConsole
/*--------------------------------------------------------------------
Open a URL
URL: The URL to open
--------------------------------------------------------------------*/
void Platform::openURL(const active::utility::String& URL) {
#if WINDOWS
std::system((String{"start "} + URL).data());
#elif __APPLE__
std::system((String{"open "} + URL).data());
#elif __linux__
std::system((String{"xdg-open"} + url).data());
#endif
} //Platform::openURL
/*--------------------------------------------------------------------
Get an object representing the parent process/application
@@ -18,6 +18,11 @@ namespace speckle::environment {
@param message The message to write
*/
void writeToConsole(const active::utility::String& message);
/*!
Open a URL
@param URL The URL to open
*/
void openURL(const active::utility::String& URL);
};
+64 -10
View File
@@ -19,6 +19,10 @@ namespace {
vertexID,
faceID,
colorID,
pointID,
closedID,
lengthID,
areaID,
};
///Serialisation field IDs
@@ -26,6 +30,10 @@ namespace {
Identity{"vertices"},
Identity{"faces"},
Identity{"colors"},
Identity{"value"},
Identity{"closed"},
Identity{"length"},
Identity{"area"},
};
}
@@ -53,6 +61,13 @@ void Mesh::appendFace(const std::vector<double>& vertices) {
return: True if the package has added items to the inventory
--------------------------------------------------------------------*/
bool Mesh::fillInventory(Inventory& inventory) const {
if (isPolyline)
return fillInventoryPolyline(inventory);
else
return fillInventoryMesh(inventory);
} //Mesh::fillInventory
bool Mesh::fillInventoryMesh(Inventory& inventory) const {
using enum Entry::Type;
inventory.merge(Inventory{
{
@@ -60,9 +75,22 @@ bool Mesh::fillInventory(Inventory& inventory) const {
{ fieldID[faceID], faceID, element },
{ fieldID[colorID], colorID, element },
},
}.withType(&typeid(Mesh)));
}.withType(&typeid(Mesh)));
return base::fillInventory(inventory);
} //Mesh::fillInventory
}
bool Mesh::fillInventoryPolyline(Inventory& inventory) const {
using enum Entry::Type;
inventory.merge(Inventory{
{
{ fieldID[pointID], pointID, element },
{ fieldID[closedID], closedID, element },
{ fieldID[lengthID], lengthID, element },
{ fieldID[areaID], areaID, element },
},
}.withType(&typeid(Mesh)));
return base::fillInventory(inventory);
}
/*--------------------------------------------------------------------
@@ -73,20 +101,46 @@ bool Mesh::fillInventory(Inventory& inventory) const {
return: The requested cargo (nullptr on failure)
--------------------------------------------------------------------*/
Cargo::Unique Mesh::getCargo(const Inventory::Item& item) const {
if (isPolyline)
return getCargoPolyline(item);
else
return getCargoMesh(item);
} //Mesh::getCargo
Cargo::Unique Mesh::getCargoMesh(const Inventory::Item& item) const {
if (item.ownerType != &typeid(Mesh))
return base::getCargo(item);
using namespace active::serialise;
switch (item.index) {
case vertexID:
return std::make_unique<ContainerWrap<std::vector<double>>>(m_vertices);
case faceID:
return std::make_unique<ContainerWrap<std::vector<int>>>(m_faces);
case colorID:
return std::make_unique<ContainerWrap<std::vector<int>>>(m_colors);
default:
return nullptr; //Requested an unknown index
return std::make_unique<ContainerWrap<std::vector<double>>>(m_vertices);
case faceID:
return std::make_unique<ContainerWrap<std::vector<int>>>(m_faces);
case colorID:
return std::make_unique<ContainerWrap<std::vector<int>>>(m_colors);
default:
return nullptr; //Requested an unknown index
}
} //Mesh::getCargo
}
Cargo::Unique Mesh::getCargoPolyline(const Inventory::Item& item) const {
if (item.ownerType != &typeid(Mesh))
return base::getCargo(item);
using namespace active::serialise;
switch (item.index) {
case pointID:
return std::make_unique<ContainerWrap<std::vector<double>>>(m_points);
case closedID:
return std::make_unique<ValueWrap<bool>>(isClosed);
case lengthID:
return std::make_unique<ValueWrap<double>>(length);
case areaID:
return std::make_unique<ValueWrap<double>>(area);
default:
return nullptr; //Requested an unknown index
}
}
/*--------------------------------------------------------------------
+23 -1
View File
@@ -43,6 +43,10 @@ namespace speckle::primitive {
Mesh(std::vector<double>&& vertices, std::vector<int>&& faces, std::vector<int>&& colors, const record::attribute::Finish& finish,
active::measure::LengthType unit = active::measure::LengthType::metre) :
base{utility::Guid{true}, utility::Guid{}, unit}, m_vertices{std::move(vertices)}, m_faces{std::move(faces)}, m_colors{std::move(colors)}, m_finish{finish} {}
Mesh(std::vector<double>&& points, const record::attribute::Finish& finish,
active::measure::LengthType unit = active::measure::LengthType::metre) :
base{ utility::Guid{true}, utility::Guid{}, unit }, m_points{ std::move(points) }, m_finish{ finish } {}
// MARK: - Functions (const)
@@ -50,7 +54,13 @@ namespace speckle::primitive {
Get the speckle type identifier
@return The speckle type (relevant objects should override as required)
*/
speckle::utility::String getSpeckleType() const override { return "Objects.Geometry.Mesh"; }
speckle::utility::String getSpeckleType() const override
{
if (isPolyline)
return "Objects.Geometry.Polyline";
else
return "Objects.Geometry.Mesh";
}
/*!
Append a single face to the Mesh given by the vertices
@@ -66,23 +76,35 @@ namespace speckle::primitive {
@return True if the package has added items to the inventory
*/
bool fillInventory(active::serialise::Inventory& inventory) const override;
bool fillInventoryMesh(active::serialise::Inventory& inventory) const;
bool fillInventoryPolyline(active::serialise::Inventory& inventory) const;
/*!
Get the specified cargo
@param item The inventory item to retrieve
@return The requested cargo (nullptr on failure)
*/
active::serialise::Cargo::Unique getCargo(const active::serialise::Inventory::Item& item) const override;
active::serialise::Cargo::Unique getCargoMesh(const active::serialise::Inventory::Item& item) const;
active::serialise::Cargo::Unique getCargoPolyline(const active::serialise::Inventory::Item& item) const;
/*!
Use a manager in (de)serialisation processes
@param management The management to use
*/
void useManagement(active::serialise::Management* management) const override;
void setToPolyline() { isPolyline = true; }
private:
std::vector<double> m_vertices;
std::vector<double> m_points;
std::vector<int> m_faces;
std::vector<int> m_colors;
record::attribute::Finish m_finish;
bool isPolyline = false;
bool isClosed = false;
double length = 2.0;
double area = 0.0;
};
}
@@ -17,6 +17,7 @@
#include <ModelElement.hpp>
#include <ModelMaterial.hpp>
#include <ModelMeshBody.hpp>
#include <ModelEdge.hpp>
#include <Sight.hpp>
#endif
@@ -32,6 +33,8 @@ using namespace speckle::utility;
#include <array>
#include <memory>
#include <stack>
namespace speckle::record::element {
class ModelElement::Data {
@@ -240,6 +243,8 @@ void ModelElement::resetCache() {
--------------------------------------------------------------------*/
ModelElement::Body* ModelElement::getBody() const {
#ifdef ARCHICAD
ModelerAPI::Material tmpmat{};
if (m_data && m_data->m_cache)
return m_data->m_cache.get();
void* dummy = nullptr;
@@ -271,6 +276,52 @@ ModelElement::Body* ModelElement::getBody() const {
ModelerAPI::MeshBody body{};
elem.GetTessellatedBody(bodyIndex, &body);
Int32 polyCount = body.GetPolygonCount();
if (polyCount == 0)
{
std::vector<int> vertexIndices;
Int32 edgeCount = body.GetEdgeCount();
ModelerAPI::Edge edge{};
for (Int32 edgeIndex = 1; edgeIndex <= edgeCount; ++edgeIndex)
{
body.GetEdge(edgeIndex, &edge);
vertexIndices.push_back(edge.GetVertexIndex1());
vertexIndices.push_back(edge.GetVertexIndex2());
}
vertexIndices.push_back(edge.GetVertexIndex2());
vertexIndices.push_back(edge.GetVertexIndex2());
for (int i = 0; i < vertexIndices.size(); i += 2) {
ModelerAPI::Vertex v1{};
ModelerAPI::Vertex v2{};
body.GetVertex(vertexIndices[i], &v1);
body.GetVertex(vertexIndices[i + 1], &v2);
std::vector<double> points{};
points.push_back(v1.x);
points.push_back(v1.y);
points.push_back(v1.z);
points.push_back(v2.x);
points.push_back(v2.y);
points.push_back(v2.z);
points.push_back(v2.x);
points.push_back(v2.y);
points.push_back(v2.z);
record::attribute::Finish f(tmpmat);
primitive::Mesh mesh(std::move(points), f);
mesh.setToPolyline();
elementBody->push_back(mesh);
points.clear();
}
}
for (Int32 polyIndex = 1; polyIndex <= polyCount; ++polyIndex) {
ModelerAPI::Polygon polygon{};
body.GetPolygon(polyIndex, &polygon);
@@ -281,6 +332,8 @@ ModelElement::Body* ModelElement::getBody() const {
if (faceFinish == nullptr) {
ModelerAPI::Material material{};
polygon.GetMaterial(&material);
///
tmpmat = material;
Finish finish{material};
faceFinish = ModelElement::cacheFinish(finishID, finish);
}
@@ -308,6 +361,13 @@ ModelElement::Body* ModelElement::getBody() const {
}
for (auto& [materialName, mesh] : materialMeshMap)
elementBody->push_back(std::move(mesh));
/*std::vector<double> points = {0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0};
record::attribute::Finish f(tmpmat);
primitive::Mesh mesh(std::move(points), f);
mesh.setToPolyline();
elementBody->push_back(mesh);*/
m_data = std::make_unique<Data>();
m_data->m_cache.reset(elementBody);
return m_data->m_cache.get();