Fix linux build.
This commit is contained in:
parent
a6d92e142f
commit
9e1d951520
50 changed files with 1586 additions and 1192 deletions
|
@ -4,6 +4,8 @@
|
|||
#include "WireNode.h"
|
||||
#include "LogicGateNode.h"
|
||||
|
||||
#include "LineNode.h"
|
||||
|
||||
#include "FileLogger.h"
|
||||
|
||||
ElectronicCircuitNode::ElectronicCircuitNode(const Transform& transform)
|
||||
|
|
|
@ -103,7 +103,7 @@ void QuantumCircuitReader::onLineEnd()
|
|||
mWorkingElement = nullptr;
|
||||
}
|
||||
|
||||
void QuantumCircuitReader::onGate(Location loc, const std::string value)
|
||||
void QuantumCircuitReader::onGate(Location, const std::string value)
|
||||
{
|
||||
MLOG_INFO("Got gate: " << value);
|
||||
|
||||
|
@ -142,7 +142,7 @@ std::string QuantumCircuitReader::checkForGate(const std::string& segment)
|
|||
return working_string;
|
||||
}
|
||||
|
||||
void QuantumCircuitReader::onKet(Location loc, const std::string value)
|
||||
void QuantumCircuitReader::onKet(Location, const std::string value)
|
||||
{
|
||||
MLOG_INFO("Got input state: " << value);
|
||||
Qubit qubit;
|
||||
|
@ -199,7 +199,7 @@ std::string QuantumCircuitReader::checkForKet(const std::string& segment)
|
|||
}
|
||||
}
|
||||
|
||||
void QuantumCircuitReader::onVertialQuantumWire(Location loc)
|
||||
void QuantumCircuitReader::onVertialQuantumWire(Location)
|
||||
{
|
||||
|
||||
}
|
|
@ -8,7 +8,6 @@ const std::vector<Qubit>& QuantumState::getData() const
|
|||
std::string QuantumState::toString() const
|
||||
{
|
||||
std::string out;
|
||||
std::size_t count{ 0 };
|
||||
for (const auto& qubit : mState)
|
||||
{
|
||||
out += "|" + qubit.toString() + "\n";
|
||||
|
|
|
@ -9,6 +9,9 @@
|
|||
#include "QuantumWireNode.h"
|
||||
#include "QuantumGateNode.h"
|
||||
|
||||
#include "LatexMathExpression.h"
|
||||
#include "EquationNode.h"
|
||||
|
||||
QuantumCircuitNode::QuantumCircuitNode(const Transform& t)
|
||||
: AbstractVisualNode(t)
|
||||
{
|
||||
|
|
|
@ -32,7 +32,7 @@ void QuantumGateNode::update(SceneInfo* sceneInfo)
|
|||
}
|
||||
}
|
||||
|
||||
void QuantumGateNode::createOrUpdateGeometry(SceneInfo* sceneInfo)
|
||||
void QuantumGateNode::createOrUpdateGeometry(SceneInfo*)
|
||||
{
|
||||
if (!mBody)
|
||||
{
|
||||
|
@ -75,14 +75,14 @@ void QuantumGateNode::createOrUpdateGeometry(SceneInfo* sceneInfo)
|
|||
Point QuantumGateNode::getConnectionLocation(AbstractQuantumWire* wire) const
|
||||
{
|
||||
bool is_input{ false };
|
||||
std::size_t connection_id{ 0 };
|
||||
//std::size_t connection_id{ 0 };
|
||||
|
||||
for (std::size_t idx = 0; idx < mContent->getNumInputs(); idx++)
|
||||
{
|
||||
if (mContent->getInput(idx) == wire)
|
||||
{
|
||||
is_input = true;
|
||||
connection_id = idx;
|
||||
//connection_id = idx;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ Point QuantumGateNode::getConnectionLocation(AbstractQuantumWire* wire) const
|
|||
{
|
||||
if (mContent->getOutput(idx) == wire)
|
||||
{
|
||||
connection_id = idx;
|
||||
//connection_id = idx;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ void QuantumTerminalNode::update(SceneInfo* sceneInfo)
|
|||
}
|
||||
}
|
||||
|
||||
void QuantumTerminalNode::createOrUpdateGeometry(SceneInfo* sceneInfo)
|
||||
void QuantumTerminalNode::createOrUpdateGeometry(SceneInfo*)
|
||||
{
|
||||
if (!mLabel && mContent->getTerminalType() != QuantumTerminal::TerminalType::OUTPUT)
|
||||
{
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "LineNode.h"
|
||||
|
||||
QuantumWireNode::QuantumWireNode(const Transform& t)
|
||||
: AbstractVisualNode(t)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -46,7 +47,7 @@ void QuantumWireNode::update(SceneInfo* sceneInfo)
|
|||
}
|
||||
}
|
||||
|
||||
void QuantumWireNode::createOrUpdateGeometry(SceneInfo* sceneInfo)
|
||||
void QuantumWireNode::createOrUpdateGeometry(SceneInfo*)
|
||||
{
|
||||
if (!mLine)
|
||||
{
|
||||
|
|
|
@ -6,6 +6,12 @@
|
|||
#include "QuantumCircuitNode.h"
|
||||
#include "QuantumCircuit.h"
|
||||
|
||||
#include "QuantumWireNode.h"
|
||||
#include "QuantumGateNode.h"
|
||||
#include "QuantumTerminalNode.h"
|
||||
#include "EquationNode.h"
|
||||
#include "LatexMathExpression.h"
|
||||
|
||||
|
||||
TEST_CASE(TestQuantumCircuitParsing, "quantum_computing")
|
||||
{
|
||||
|
|
|
@ -3,6 +3,8 @@ set(MODULE_NAME geometry)
|
|||
list(APPEND HEADERS
|
||||
AbstractGeometricItem.h
|
||||
Bounds.h
|
||||
Transform.h
|
||||
Rotation.h
|
||||
grid/AbstractGrid.h
|
||||
grid/TypedGrid.h
|
||||
grid/Grid.h
|
||||
|
@ -30,6 +32,7 @@ list(APPEND HEADERS
|
|||
)
|
||||
|
||||
list(APPEND SOURCES
|
||||
Rotation.cpp
|
||||
Transform.cpp
|
||||
grid/AbstractGrid.cpp
|
||||
math/Linalg.cpp
|
||||
|
|
31
src/base/geometry/Rotation.cpp
Normal file
31
src/base/geometry/Rotation.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
#include "Rotation.h"
|
||||
|
||||
Rotation::Rotation(double angle, Axis axis, const Point& loc, const Vector& customAxis)
|
||||
: mAngle(angle),
|
||||
mAxis(axis),
|
||||
mPoint(loc),
|
||||
mCustomAxis(customAxis),
|
||||
mMatrix(3, 3)
|
||||
{
|
||||
updateMatrix();
|
||||
}
|
||||
|
||||
const Matrix& Rotation::getMatrix() const
|
||||
{
|
||||
return mMatrix;
|
||||
}
|
||||
|
||||
bool Rotation::isIdentity() const
|
||||
{
|
||||
return mMatrix.isIdentity();
|
||||
}
|
||||
|
||||
bool Rotation::isEqual(const Rotation& rotation) const
|
||||
{
|
||||
return mMatrix == rotation.mMatrix;
|
||||
}
|
||||
|
||||
void Rotation::updateMatrix()
|
||||
{
|
||||
|
||||
}
|
45
src/base/geometry/Rotation.h
Normal file
45
src/base/geometry/Rotation.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
#pragma once
|
||||
|
||||
#include "Point.h"
|
||||
#include "Vector.h"
|
||||
#include "Matrix.h"
|
||||
|
||||
class Rotation
|
||||
{
|
||||
public:
|
||||
enum class Axis
|
||||
{
|
||||
X,
|
||||
Y,
|
||||
Z,
|
||||
USER
|
||||
};
|
||||
|
||||
Rotation(double angle = 0.0, Axis axis = Axis::Z, const Point& loc = {}, const Vector& customAxis = {});
|
||||
|
||||
const Matrix& getMatrix() const;
|
||||
|
||||
bool isIdentity() const;
|
||||
|
||||
bool isEqual(const Rotation& rotation) const;
|
||||
|
||||
bool operator==(const Rotation& rhs) const
|
||||
{
|
||||
return isEqual(rhs);
|
||||
}
|
||||
|
||||
bool operator!=(const Rotation& rhs) const
|
||||
{
|
||||
return !operator==(rhs);
|
||||
}
|
||||
|
||||
private:
|
||||
void updateMatrix();
|
||||
|
||||
double mAngle{ 0 };
|
||||
Axis mAxis{ Axis::Z };
|
||||
Point mPoint;
|
||||
Vector mCustomAxis;
|
||||
|
||||
Matrix mMatrix;
|
||||
};
|
|
@ -1,43 +1,92 @@
|
|||
#include "Transform.h"
|
||||
|
||||
Transform::Transform(const Point& location, double scaleX, double scaleY, double scaleZ)
|
||||
: mLocation(location),
|
||||
mScaleX(scaleX),
|
||||
mScaleY(scaleY),
|
||||
mScaleZ(scaleZ)
|
||||
Scale::Scale(double x, double y, double z)
|
||||
: mX(x),
|
||||
mY(y),
|
||||
mZ(z)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool Scale::isIdentity() const
|
||||
{
|
||||
return mX == 1.0 && mY == 1.0 && mZ == 1.0;
|
||||
}
|
||||
|
||||
bool Scale::isEqual(const Scale& scale) const
|
||||
{
|
||||
return mX == scale.mX && mY == scale.mY && mZ == scale.mZ;
|
||||
}
|
||||
|
||||
Transform::Transform(const Point& location, const Scale& scale, const Rotation& rotation)
|
||||
: mLocation(location),
|
||||
mScale(scale),
|
||||
mRotation(rotation),
|
||||
mMatrix(4, 4)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Transform::applyPre(const Transform& transform)
|
||||
{
|
||||
mLocation.move(transform.getLocation().getX(), transform.getLocation().getY(), transform.getLocation().getZ());
|
||||
mScale *= transform.getScale();
|
||||
}
|
||||
|
||||
const Point& Transform::getLocation() const
|
||||
{
|
||||
return mLocation;
|
||||
}
|
||||
|
||||
double Transform::getScaleX() const
|
||||
const Scale& Transform::getScale() const
|
||||
{
|
||||
return mScaleX;
|
||||
return mScale;
|
||||
}
|
||||
|
||||
double Transform::getScaleY() const
|
||||
const Rotation& Transform::getRotation() const
|
||||
{
|
||||
return mScaleY;
|
||||
return mRotation;
|
||||
}
|
||||
|
||||
double Transform::getScaleZ() const
|
||||
bool Transform::isEqual(const Transform& transform) const
|
||||
{
|
||||
return mScaleZ;
|
||||
return (mLocation == transform.mLocation) && (mScale == transform.mScale) && (mRotation == transform.mRotation);
|
||||
}
|
||||
|
||||
bool Transform::isIdentityTransform() const
|
||||
{
|
||||
return mLocation.isAtOrigin() && mScale.isIdentity();
|
||||
}
|
||||
|
||||
void Transform::setLocation(const Point& loc)
|
||||
{
|
||||
if (mLocation != loc)
|
||||
{
|
||||
mLocation = loc;
|
||||
updateMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
void Transform::setScale(double scaleX, double scaleY, double scaleZ)
|
||||
void Transform::setScale(const Scale& scale)
|
||||
{
|
||||
if (mScale != scale)
|
||||
{
|
||||
mScale = scale;
|
||||
updateMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
void Transform::setRotation(const Rotation& rotation)
|
||||
{
|
||||
if (mRotation != rotation)
|
||||
{
|
||||
mRotation = rotation;
|
||||
updateMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
void Transform::updateMatrix()
|
||||
{
|
||||
mScaleX = scaleX;
|
||||
mScaleY = scaleY;
|
||||
mScaleZ = scaleZ;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,68 +1,65 @@
|
|||
#pragma once
|
||||
|
||||
#include "Point.h"
|
||||
#include "Vector.h"
|
||||
|
||||
class Rotation
|
||||
{
|
||||
public:
|
||||
enum class Axis
|
||||
{
|
||||
X,
|
||||
Y,
|
||||
Z,
|
||||
USER
|
||||
};
|
||||
|
||||
|
||||
Rotation(double angle = 0.0, Axis axis = Axis::Z, const Point& loc = {}, const Vector& customAxis = {})
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
double mAngle{ 0 };
|
||||
Axis mAxis{ Axis::Z };
|
||||
Point mPoint;
|
||||
Vector mCustomAxis;
|
||||
};
|
||||
#include "Rotation.h"
|
||||
|
||||
struct Scale
|
||||
{
|
||||
Scale(double x = 1.0, double y = 1.0, double z = 1.0);
|
||||
|
||||
bool isIdentity() const;
|
||||
|
||||
bool isEqual(const Scale& scale) const;
|
||||
|
||||
void operator*=(const Scale& rhs)
|
||||
{
|
||||
mX *= rhs.mX;
|
||||
mY *= rhs.mY;
|
||||
mZ *= rhs.mZ;
|
||||
}
|
||||
|
||||
bool operator==(const Scale& rhs) const
|
||||
{
|
||||
return isEqual(rhs);
|
||||
}
|
||||
|
||||
bool operator!=(const Scale& rhs) const
|
||||
{
|
||||
return !operator==(rhs);
|
||||
}
|
||||
|
||||
double mX{1.0};
|
||||
double mY{1.0};
|
||||
double mZ{1.0};
|
||||
};
|
||||
|
||||
class Transform
|
||||
{
|
||||
public:
|
||||
Transform(const Point& location = {}, double scaleX = 1.0, double scaleY = 1.0, double scaleZ = 1.0);
|
||||
Transform(const Point& location = {}, const Scale& scale = {}, const Rotation& rotation = {});
|
||||
|
||||
void applyPre(const Transform& transform)
|
||||
{
|
||||
mLocation.move(transform.getLocation().getX(), transform.getLocation().getY(), transform.getLocation().getZ());
|
||||
mScaleX *= transform.getScaleX();
|
||||
mScaleY *= transform.getScaleY();
|
||||
mScaleZ *= transform.getScaleZ();
|
||||
}
|
||||
|
||||
void setLocation(const Point& loc);
|
||||
|
||||
void setScale(double scaleX, double scaleY = 1.0, double scaleZ = 1.0);
|
||||
void applyPre(const Transform& transform);
|
||||
|
||||
const Point& getLocation() const;
|
||||
|
||||
double getScaleX() const;
|
||||
const Scale& getScale() const;
|
||||
|
||||
double getScaleY() const;
|
||||
const Rotation& getRotation() const;
|
||||
|
||||
double getScaleZ() const;
|
||||
const Matrix& getMatrix() const;
|
||||
|
||||
bool isEqual(const Transform& transform) const;
|
||||
|
||||
bool isIdentityTransform() const;
|
||||
|
||||
void setLocation(const Point& loc);
|
||||
|
||||
void setScale(const Scale& scale);
|
||||
|
||||
void setRotation(const Rotation& rotation);
|
||||
|
||||
bool operator==(const Transform& rhs) const
|
||||
{
|
||||
return (mLocation == rhs.mLocation)
|
||||
&& (mScaleX == rhs.mScaleX)
|
||||
&& (mScaleY == rhs.mScaleY)
|
||||
&& (mScaleZ == rhs.mScaleZ);
|
||||
return isEqual(rhs);
|
||||
}
|
||||
|
||||
bool operator!=(const Transform& rhs) const
|
||||
|
@ -70,24 +67,11 @@ public:
|
|||
return !operator==(rhs);
|
||||
}
|
||||
|
||||
bool hasDefaultLocation() const
|
||||
{
|
||||
return mLocation.getX() == 0.0 && mLocation.getY() == 0.0 && mLocation.getZ() == 0.0;
|
||||
}
|
||||
|
||||
bool hasDefaultScale() const
|
||||
{
|
||||
return mScaleX == 1.0 && mScaleY == 1.0 && mScaleZ == 1.0;
|
||||
}
|
||||
|
||||
bool isDefaultTransform() const
|
||||
{
|
||||
return hasDefaultLocation() && hasDefaultScale();
|
||||
}
|
||||
|
||||
private:
|
||||
void updateMatrix();
|
||||
|
||||
Point mLocation;
|
||||
double mScaleX{1};
|
||||
double mScaleY{1};
|
||||
double mScaleZ{1};
|
||||
Scale mScale;
|
||||
Rotation mRotation;
|
||||
Matrix mMatrix;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
#include "Matrix.h"
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
|
||||
Matrix::Matrix(std::size_t numRows, std::size_t numColumns)
|
||||
: mNumRows(numRows),
|
||||
mNumColumns(numColumns)
|
||||
{
|
||||
mData = std::vector<double>(numRows * numColumns, 0.0);
|
||||
}
|
||||
|
||||
bool Matrix::isIdentity() const
|
||||
{
|
||||
if (!isSquare())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for(std::size_t idx=0; idx<mNumRows; idx++)
|
||||
{
|
||||
for(std::size_t jdx=0; jdx<mNumColumns; jdx++)
|
||||
{
|
||||
if (idx == jdx)
|
||||
{
|
||||
if (getItem(idx, jdx) != 1.0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (getItem(idx, jdx) != 0.0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
double Matrix::getItem(std::size_t rowId, std::size_t columnId) const
|
||||
{
|
||||
const auto index = getFlatIndex(rowId, columnId);
|
||||
if (index >= mData.size())
|
||||
{
|
||||
throw std::range_error("Out of bounds array access: " + std::to_string(index) + " for size " + std::to_string(mData.size()));
|
||||
}
|
||||
return mData[getFlatIndex(rowId, columnId)];
|
||||
}
|
||||
|
||||
bool Matrix::isSquare() const
|
||||
{
|
||||
return mNumRows == mNumColumns;
|
||||
}
|
||||
|
||||
bool Matrix::isEqual(const Matrix& matrix) const
|
||||
{
|
||||
return mData == matrix.mData;
|
||||
}
|
||||
|
||||
std::size_t Matrix::getFlatIndex(std::size_t rowId, std::size_t columnId) const
|
||||
{
|
||||
return columnId + rowId*mNumColumns;
|
||||
}
|
|
@ -5,10 +5,30 @@
|
|||
class Matrix
|
||||
{
|
||||
public:
|
||||
Matrix(unsigned numRows, unsigned numColumns)
|
||||
Matrix(std::size_t numRows, std::size_t numColumns);
|
||||
|
||||
std::size_t getFlatIndex(std::size_t rowId, std::size_t columnId) const;
|
||||
|
||||
double getItem(std::size_t rowId, std::size_t columnId) const;
|
||||
|
||||
bool isIdentity() const;
|
||||
|
||||
bool isSquare() const;
|
||||
|
||||
bool isEqual(const Matrix& matrix) const;
|
||||
|
||||
bool operator==(const Matrix& rhs) const
|
||||
{
|
||||
mData = std::vector<double>(numRows * numColumns, 0.0);
|
||||
return isEqual(rhs);
|
||||
}
|
||||
|
||||
bool operator!=(const Matrix& rhs) const
|
||||
{
|
||||
return !operator==(rhs);
|
||||
}
|
||||
|
||||
private:
|
||||
std::size_t mNumRows{0};
|
||||
std::size_t mNumColumns{0};
|
||||
std::vector<double> mData;
|
||||
};
|
|
@ -79,15 +79,20 @@ double Point::getDeltaZ(const Point& point) const
|
|||
return point.getZ() - mZ;
|
||||
}
|
||||
|
||||
bool Point::isAtOrigin() const
|
||||
{
|
||||
return mX == 0.0 && mY == 0.0 && mZ == 0.0;
|
||||
}
|
||||
|
||||
void Point::apply(const Transform& transform)
|
||||
{
|
||||
mX -= transform.getLocation().getX();
|
||||
mY -= transform.getLocation().getY();
|
||||
mZ -= transform.getLocation().getZ();
|
||||
|
||||
mX *= transform.getScaleX();
|
||||
mY *= transform.getScaleY();
|
||||
mZ *= transform.getScaleZ();
|
||||
mX *= transform.getScale().mX;
|
||||
mY *= transform.getScale().mY;
|
||||
mZ *= transform.getScale().mZ;
|
||||
}
|
||||
|
||||
void Point::move(double x, double y, double z)
|
||||
|
|
|
@ -22,6 +22,8 @@ public:
|
|||
|
||||
void apply(const Transform& transform);
|
||||
|
||||
bool isAtOrigin() const;
|
||||
|
||||
void move(double x, double y, double z = 0);
|
||||
|
||||
double getX() const;
|
||||
|
|
|
@ -7,10 +7,8 @@ if(UNIX)
|
|||
list(APPEND platform_INCLUDES
|
||||
sockets/BerkeleySocket.h
|
||||
sockets/BerkeleySocket.cpp
|
||||
sockets/UnixSocketInterface.h
|
||||
sockets/UnixSocketInterface.cpp
|
||||
server/UnixSockerServer.h
|
||||
server/UnixSockerServer.cpp
|
||||
server/UnixSocketServer.h
|
||||
server/UnixSocketServer.cpp
|
||||
client/unix/UnixSocketClient.h
|
||||
client/unix/UnixSocketClient.cpp
|
||||
)
|
||||
|
@ -45,7 +43,6 @@ list(APPEND HEADERS
|
|||
server/HttpServer.h
|
||||
server/PlatformSocketServer.h
|
||||
sockets/Socket.h
|
||||
sockets/SocketInterface.h
|
||||
sockets/IPlatformSocket.h
|
||||
)
|
||||
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
#include "UnixSocketClient.h"
|
||||
|
||||
UnixSocketClient::UnixSocketClient()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
UnixSocketClient::~UnixSocketClient()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
UnixSocketClient::Result UnixSocketClient::request(const Address& address, const std::string& message)
|
||||
{
|
||||
UnixSocketClient::Result result;
|
||||
|
||||
auto socket = std::make_unique<BerkeleySocket>(address.mHost, address.mPort);
|
||||
auto response = socket->send(message);
|
||||
|
||||
if (socket->getState().mConnectStatus != Socket::State::ConnectStatus::FAILED)
|
||||
{
|
||||
result.mStatus = UnixSocketClient::Result::Status::OK;
|
||||
result.mBody = response;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.mStatus = UnixSocketClient::Result::Status::FAILED;
|
||||
result.mErrorCode = socket->getState().mErrorCode;
|
||||
result.mErrorMessage = socket->getState().mErrorMessage;
|
||||
}
|
||||
return result;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
#include "BerkeleySocket.h"
|
||||
|
||||
#include "PlatformSocketClient.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
class UnixSocketClient : public PlatformSocketClient
|
||||
{
|
||||
public:
|
||||
UnixSocketClient();
|
||||
|
||||
virtual ~UnixSocketClient();
|
||||
|
||||
Result request(const Address& address, const std::string& message);
|
||||
};
|
|
@ -0,0 +1,70 @@
|
|||
#include "UnixSocketServer.h"
|
||||
|
||||
#include "BerkeleySocket.h"
|
||||
|
||||
#include "FileLogger.h"
|
||||
|
||||
#include <thread>
|
||||
|
||||
UnixSocketServer::~UnixSocketServer()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void UnixSocketServer::listen(const Address& address, onConnectionSuccessFunc connectionSuccessFunc, onConnectionFailedFunc connectionFailedFunc)
|
||||
{
|
||||
mConnectionCallback = connectionSuccessFunc;
|
||||
mFailedCallback = connectionFailedFunc;
|
||||
|
||||
auto server_socket = std::make_unique<BerkeleySocket>(address.mHost, address.mPort);
|
||||
|
||||
auto on_connection = [this](int handle)
|
||||
{
|
||||
auto socket = std::make_unique<BerkeleySocket>(handle);
|
||||
this->onConnection(std::move(socket));
|
||||
};
|
||||
server_socket->doListen(on_connection);
|
||||
|
||||
if (server_socket->getState().mBindStatus == Socket::State::BindStatus::FAILED)
|
||||
{
|
||||
UnixSocketServer::Result result;
|
||||
result.mStatus = UnixSocketServer::Result::Status::FAILED;
|
||||
result.mErrorCode = server_socket->getState().mErrorCode;
|
||||
result.mErrorMessage = server_socket->getState().mErrorMessage;
|
||||
mFailedCallback(result);
|
||||
}
|
||||
}
|
||||
|
||||
void UnixSocketServer::shutDown()
|
||||
{
|
||||
mThreads.removeMarked();
|
||||
mThreads.joinAndClearAll();
|
||||
}
|
||||
|
||||
void UnixSocketServer::onConnection(std::unique_ptr<BerkeleySocket> s)
|
||||
{
|
||||
// House-keeping first - clean up any finished threads
|
||||
MLOG_INFO("Before thread cleanup: " << mThreads.size());
|
||||
|
||||
mThreads.removeMarked();
|
||||
|
||||
MLOG_INFO("After thread cleanup: " << mThreads.size());
|
||||
|
||||
auto worker_func = [this](std::unique_ptr<BerkeleySocket> s)
|
||||
{
|
||||
MLOG_INFO("Spawned thread for new connection");
|
||||
|
||||
mConnectionCallback(s.get());
|
||||
|
||||
MLOG_INFO("Finished thread for new connection");
|
||||
this->onThreadComplete(std::this_thread::get_id());
|
||||
};
|
||||
|
||||
auto worker = std::make_unique<std::thread>(worker_func, std::move(s));
|
||||
mThreads.add(std::move(worker));
|
||||
};
|
||||
|
||||
void UnixSocketServer::onThreadComplete(std::thread::id id)
|
||||
{
|
||||
mThreads.markForRemoval(id);
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
#pragma once
|
||||
|
||||
#include "PlatformSocketServer.h"
|
||||
#include "ThreadCollection.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class BerkeleySocket;
|
||||
|
||||
class UnixSocketServer : public PlatformSocketServer
|
||||
{
|
||||
public:
|
||||
virtual ~UnixSocketServer();
|
||||
|
||||
void listen(const Address& address, onConnectionSuccessFunc connectionSuccessFunc, onConnectionFailedFunc connectionFailedFunc) override;
|
||||
|
||||
void shutDown() override;
|
||||
|
||||
private:
|
||||
void onConnection(std::unique_ptr<BerkeleySocket> clientHandle);
|
||||
|
||||
void onThreadComplete(std::thread::id id);
|
||||
|
||||
ThreadCollection mThreads;
|
||||
onConnectionSuccessFunc mConnectionCallback;
|
||||
onConnectionFailedFunc mFailedCallback;
|
||||
};
|
|
@ -0,0 +1,184 @@
|
|||
#include "BerkeleySocket.h"
|
||||
|
||||
#include "FileLogger.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
BerkeleySocket::BerkeleySocket(const std::string& address, unsigned port)
|
||||
: Socket(address, port)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
BerkeleySocket::BerkeleySocket(int handle)
|
||||
: Socket("", 0),
|
||||
mHandle(handle)
|
||||
{
|
||||
mState.mConnectStatus = State::ConnectStatus::OK;
|
||||
}
|
||||
|
||||
BerkeleySocket::~BerkeleySocket()
|
||||
{
|
||||
MLOG_INFO("Socket being destroyed");
|
||||
}
|
||||
|
||||
void BerkeleySocket::initialize()
|
||||
{
|
||||
mHandle = ::socket(AF_INET, SOCK_STREAM, 0);
|
||||
}
|
||||
|
||||
void BerkeleySocket::initializeForBind()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void BerkeleySocket::doConnect()
|
||||
{
|
||||
struct sockaddr_in serv_addr;
|
||||
memset(&serv_addr, 0, sizeof(serv_addr));
|
||||
serv_addr.sin_family = AF_INET;
|
||||
|
||||
::inet_aton(mAddress.c_str(), &serv_addr.sin_addr);
|
||||
serv_addr.sin_port = ::htons(mPort);
|
||||
|
||||
int result = ::connect(mHandle, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
|
||||
if( result < 0)
|
||||
{
|
||||
mState.mConnectStatus = Socket::State::ConnectStatus::FAILED;
|
||||
mState.mErrorCode = result;
|
||||
mState.mErrorMessage = "Socket: Unable to connect to server.";
|
||||
return;
|
||||
}
|
||||
mState.mConnectStatus = Socket::State::ConnectStatus::OK;
|
||||
}
|
||||
|
||||
void BerkeleySocket::doBind()
|
||||
{
|
||||
struct sockaddr_in serv_addr;
|
||||
memset(&serv_addr, 0, sizeof(serv_addr));
|
||||
serv_addr.sin_family = AF_INET;
|
||||
serv_addr.sin_addr.s_addr = INADDR_ANY;
|
||||
serv_addr.sin_port = htons(mPort);
|
||||
|
||||
int result = ::bind(mHandle, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
|
||||
if (result< 0)
|
||||
{
|
||||
mState.mBindStatus = Socket::State::BindStatus::FAILED;
|
||||
mState.mErrorCode = result;
|
||||
mState.mErrorMessage = "Socket: Unable to bind socket";
|
||||
return;
|
||||
}
|
||||
mState.mBindStatus = Socket::State::BindStatus::OK;
|
||||
}
|
||||
|
||||
void BerkeleySocket::doListen(onIncomingConnectionFunc connectionFunc)
|
||||
{
|
||||
initializeForBind();
|
||||
if (mState.mBindStatus == Socket::State::BindStatus::FAILED)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
doBind();
|
||||
if (mState.mBindStatus == Socket::State::BindStatus::FAILED)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
::listen(mHandle, 5);
|
||||
|
||||
struct sockaddr_in cli_addr;
|
||||
socklen_t clilen = sizeof(cli_addr);
|
||||
while(true)
|
||||
{
|
||||
const auto new_socket_handle = ::accept(mHandle, (struct sockaddr *) &cli_addr, &clilen);
|
||||
if (new_socket_handle < 0)
|
||||
{
|
||||
mState.mBindStatus = Socket::State::BindStatus::FAILED;
|
||||
mState.mErrorCode = new_socket_handle;
|
||||
mState.mErrorMessage = "Socket: Accept failed";
|
||||
::close(mHandle);
|
||||
return;
|
||||
}
|
||||
connectionFunc(new_socket_handle);
|
||||
}
|
||||
}
|
||||
|
||||
std::string BerkeleySocket::send(const std::string& message)
|
||||
{
|
||||
if (mState.mConnectStatus != Socket::State::ConnectStatus::OK)
|
||||
{
|
||||
initialize();
|
||||
if (mState.mConnectStatus == Socket::State::ConnectStatus::FAILED)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
doConnect();
|
||||
if (mState.mConnectStatus == Socket::State::ConnectStatus::FAILED)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
auto n = ::write(mHandle, message.c_str(), message.length());
|
||||
if (n < 0)
|
||||
{
|
||||
onSockerError("Socket: Send failed.");
|
||||
return{};
|
||||
}
|
||||
|
||||
std::string response;
|
||||
while (mState.mConnectStatus == Socket::State::ConnectStatus::OK)
|
||||
{
|
||||
response += recieve();
|
||||
}
|
||||
::close(mHandle);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
void BerkeleySocket::respond(const std::string& message)
|
||||
{
|
||||
auto result = ::write(mHandle, message.c_str(), static_cast<int>(message.size()));
|
||||
(void)result;
|
||||
}
|
||||
|
||||
void BerkeleySocket::onSockerError(const std::string& message)
|
||||
{
|
||||
mState.mErrorCode = -1;
|
||||
mState.mErrorMessage = message;
|
||||
|
||||
if (mState.mConnectStatus == Socket::State::ConnectStatus::OK)
|
||||
{
|
||||
::close(mHandle);
|
||||
}
|
||||
mState.mConnectStatus = Socket::State::ConnectStatus::FAILED;
|
||||
}
|
||||
|
||||
std::string BerkeleySocket::recieve()
|
||||
{
|
||||
const int BUFFER_SIZE = 512;
|
||||
char buffer[BUFFER_SIZE];
|
||||
auto result = ::read(mHandle, buffer, BUFFER_SIZE);
|
||||
if (result > 0)
|
||||
{
|
||||
return std::string(buffer);
|
||||
}
|
||||
else if (result == 0)
|
||||
{
|
||||
mState.mConnectStatus = Socket::State::ConnectStatus::UNSET;
|
||||
}
|
||||
else
|
||||
{
|
||||
mState.mConnectStatus = Socket::State::ConnectStatus::FAILED;
|
||||
mState.mErrorCode = result;
|
||||
mState.mErrorMessage = "Socket: read failed.";
|
||||
}
|
||||
return {};
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
#pragma once
|
||||
|
||||
#include "Socket.h"
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
class BerkeleySocket : public Socket
|
||||
{
|
||||
public:
|
||||
BerkeleySocket(const std::string& address, unsigned port);
|
||||
|
||||
BerkeleySocket(int handle);
|
||||
|
||||
~BerkeleySocket();
|
||||
|
||||
std::string recieve() override;
|
||||
|
||||
void respond(const std::string& message) override;
|
||||
|
||||
std::string send(const std::string& message) override;
|
||||
|
||||
using onIncomingConnectionFunc = std::function<void(int)>;
|
||||
void doListen(onIncomingConnectionFunc connectionFunc);
|
||||
|
||||
private:
|
||||
void initialize() override;
|
||||
void initializeForBind() override;
|
||||
|
||||
void doConnect() override;
|
||||
|
||||
void doBind() override;
|
||||
|
||||
void onSockerError(const std::string& message);
|
||||
|
||||
int mHandle{ 0 };
|
||||
};
|
|
@ -1,17 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class Socket;
|
||||
using SocketPtr = std::unique_ptr<Socket>;
|
||||
|
||||
class ISocketInterface
|
||||
{
|
||||
public:
|
||||
ISocketInterface() = default;
|
||||
|
||||
virtual ~ISocketInterface() = default;
|
||||
};
|
||||
|
||||
using ISocketInterfaceUPtr = std::unique_ptr<ISocketInterface>;
|
|
@ -1,146 +0,0 @@
|
|||
#include "UnixSocketInterface.h"
|
||||
|
||||
#include "HttpResponse.h"
|
||||
#include "HttpMessageHandler.h"
|
||||
|
||||
#include "FileLogger.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
UnixSocketInterface::UnixSocketInterface()
|
||||
{
|
||||
mMessageHandler = std::make_unique<HttpMessageHandler>();
|
||||
}
|
||||
|
||||
std::unique_ptr<UnixSocketInterface> UnixSocketInterface::Create()
|
||||
{
|
||||
return std::make_unique<UnixSocketInterface>();
|
||||
}
|
||||
|
||||
UnixSocketInterface::~UnixSocketInterface()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void UnixSocketInterface::initializeSocket(const SocketPtr& socketPtr, const std::string& address)
|
||||
{
|
||||
auto handle = ::socket(AF_INET, SOCK_STREAM, 0);
|
||||
socketPtr->setHandle(handle);
|
||||
|
||||
if (!address.empty())
|
||||
{
|
||||
socketPtr->setAddress(address);
|
||||
}
|
||||
}
|
||||
|
||||
void UnixSocketInterface::socketWrite(const SocketPtr& socket, const std::string& message)
|
||||
{
|
||||
if(socket->getHandle() < 0)
|
||||
{
|
||||
MLOG_ERROR("Error opening socket" );
|
||||
return;
|
||||
}
|
||||
|
||||
const auto port = static_cast<int>(socket->getPort());
|
||||
struct sockaddr_in serv_addr;
|
||||
memset(&serv_addr, 0, sizeof(serv_addr));
|
||||
serv_addr.sin_family = AF_INET;
|
||||
|
||||
inet_aton(socket->getAddress().c_str(), &serv_addr.sin_addr);
|
||||
serv_addr.sin_port = htons(port);
|
||||
|
||||
int result = connect(socket->getHandle(), (struct sockaddr *)&serv_addr, sizeof(serv_addr));
|
||||
if(result< 0)
|
||||
{
|
||||
MLOG_ERROR("Error connecting to socket" );
|
||||
return;
|
||||
}
|
||||
|
||||
auto n = write(socket->getHandle(), message.c_str(), message.length());
|
||||
if (n < 0)
|
||||
{
|
||||
std::cerr << "Error on write" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
char buffer[BUFFER_SIZE] = {0};
|
||||
int res = read(socket->getHandle(), buffer, BUFFER_SIZE);
|
||||
if (res < 0)
|
||||
{
|
||||
std::cerr << "Error on read" << std::endl;
|
||||
return;
|
||||
}
|
||||
socket->setMessage(buffer);
|
||||
std::cout << "Here is the message: " << buffer << std::endl;
|
||||
}
|
||||
|
||||
void UnixSocketInterface::socketListen(const SocketPtr& socket)
|
||||
{
|
||||
if(socket->getHandle() < 0)
|
||||
{
|
||||
std::cerr << "Error opening socket" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
const auto port = static_cast<int>(socket->getPort());
|
||||
struct sockaddr_in serv_addr;
|
||||
memset(&serv_addr, 0, sizeof(serv_addr));
|
||||
serv_addr.sin_family = AF_INET;
|
||||
serv_addr.sin_addr.s_addr = INADDR_ANY;
|
||||
serv_addr.sin_port = htons(port);
|
||||
|
||||
int result = bind(socket->getHandle(), (struct sockaddr *)&serv_addr, sizeof(serv_addr));
|
||||
if(result< 0)
|
||||
{
|
||||
std::cerr << "Error binding socket" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
listen(socket->getHandle(), 5);
|
||||
}
|
||||
|
||||
void UnixSocketInterface::run(const SocketPtr& socket)
|
||||
{
|
||||
if(socket->getHandle() < 0)
|
||||
{
|
||||
std::cerr << "Error opening socket" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
struct sockaddr_in cli_addr;
|
||||
socklen_t clilen = sizeof(cli_addr);
|
||||
while(true)
|
||||
{
|
||||
const auto new_socket_handle = accept(socket->getHandle(), (struct sockaddr *) &cli_addr, &clilen);
|
||||
if (new_socket_handle < 0)
|
||||
{
|
||||
std::cerr << "Error on accept" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
char buffer[BUFFER_SIZE] = {0};
|
||||
int n = read(new_socket_handle, buffer, BUFFER_SIZE);
|
||||
if (n < 0)
|
||||
{
|
||||
std::cerr << "Error on read" << std::endl;
|
||||
return;
|
||||
}
|
||||
socket->setMessage(buffer);
|
||||
std::cout << "Here is the message: " << buffer << std::endl;
|
||||
|
||||
const auto response = mMessageHandler->onMessage(buffer);
|
||||
n = write(new_socket_handle, response.c_str(), response.length());
|
||||
if (n < 0)
|
||||
{
|
||||
std::cerr << "Error on write" << std::endl;
|
||||
return;
|
||||
}
|
||||
close(new_socket_handle);
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "Socket.h"
|
||||
#include "SocketInterface.h"
|
||||
|
||||
#include <memory>
|
||||
#include <map>
|
||||
|
||||
class ISocketMessageHandler;
|
||||
|
||||
class UnixSocketInterface : public ISocketInterface
|
||||
{
|
||||
public:
|
||||
UnixSocketInterface();
|
||||
|
||||
virtual ~UnixSocketInterface();
|
||||
|
||||
static std::unique_ptr<UnixSocketInterface> Create();
|
||||
|
||||
void initializeSocket(const SocketPtr& socket, const std::string& address = {}) override;
|
||||
|
||||
void socketListen(const SocketPtr& socket) override;
|
||||
|
||||
void socketWrite(const SocketPtr& socket, const std::string& message) override;
|
||||
|
||||
void run(const SocketPtr& socket) override;
|
||||
|
||||
private:
|
||||
static constexpr unsigned BUFFER_SIZE{1024};
|
||||
std::unique_ptr<ISocketMessageHandler> mMessageHandler;
|
||||
};
|
||||
|
||||
using UnixSocketInterfacePtr = std::unique_ptr<UnixSocketInterface>;
|
|
@ -1,8 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "SocketInterface.h"
|
||||
|
||||
class WinsockInterface : public ISocketInterface
|
||||
class WinsockInterface
|
||||
{
|
||||
public:
|
||||
~WinsockInterface();
|
||||
|
|
|
@ -296,7 +296,7 @@ const std::vector<LatexMathSymbol>& LatexMathExpression::getSymbols() const
|
|||
return mSymbols;
|
||||
}
|
||||
|
||||
const LatexMathExpression::Type LatexMathExpression::getType() const
|
||||
LatexMathExpression::Type LatexMathExpression::getType() const
|
||||
{
|
||||
return mType;
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ public:
|
|||
|
||||
const LatexMathSymbol& getRightSymbol() const;
|
||||
|
||||
const Type getType() const;
|
||||
Type getType() const;
|
||||
|
||||
void setLeftSymbol(const LatexMathSymbol& symbol);
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include "PlotSeriesNode.h"
|
||||
|
||||
#include "LineNode.h"
|
||||
#include "EquationNode.h"
|
||||
#include "TextNode.h"
|
||||
|
||||
|
||||
PlotNode::PlotNode(const Transform& transform)
|
||||
|
@ -36,7 +38,7 @@ void PlotNode::setAxisEndStyle(LineEndNode::Style style)
|
|||
}
|
||||
}
|
||||
|
||||
void PlotNode::createOrUpdateGeometry(SceneInfo* sceneInfo)
|
||||
void PlotNode::createOrUpdateGeometry(SceneInfo*)
|
||||
{
|
||||
const double height = 100.0;
|
||||
const double width = 100.0;
|
||||
|
|
|
@ -9,7 +9,6 @@ class LineNode;
|
|||
class PlotCaptionNode;
|
||||
class PlotSeriesNode;
|
||||
|
||||
|
||||
class PlotNode : public AbstractVisualNode
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -20,6 +20,11 @@ public:
|
|||
|
||||
std::unique_ptr<FontGlyph> loadGlyph(uint32_t charCode) override;
|
||||
|
||||
double getHorizontalAdvance(const FontItem&, const std::string&) override
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
private:
|
||||
std::filesystem::path mSystemFontLocation{"/usr/share/fonts/"};
|
||||
|
||||
|
|
|
@ -102,12 +102,12 @@ void OpenGlMeshPainter::paint(SceneModel* model, DrawingContext* context)
|
|||
{
|
||||
if (idx % 3 == 0)
|
||||
{
|
||||
auto x = vertices[idx]*transform.getScaleX() + transform.getLocation().getX();
|
||||
auto x = vertices[idx]*transform.getScale().mX + transform.getLocation().getX();
|
||||
vertices[idx] = 2*x/width - 1.0;
|
||||
}
|
||||
else if(idx%3 == 1)
|
||||
{
|
||||
auto y = vertices[idx]*transform.getScaleY() + transform.getLocation().getY();
|
||||
auto y = vertices[idx]*transform.getScale().mY + transform.getLocation().getY();
|
||||
vertices[idx] = 1.0 - 2*y/height;
|
||||
}
|
||||
|
||||
|
@ -124,7 +124,7 @@ void OpenGlMeshPainter::paint(SceneModel* model, DrawingContext* context)
|
|||
indices = dynamic_cast<TriMesh*>(model->getMesh())->getFaceNodeIds();
|
||||
}
|
||||
|
||||
auto model_color = model->getFillColor().getAsVectorDouble();
|
||||
auto model_color = model->getSolidMaterial().getFillColor().getAsVectorDouble();
|
||||
std::vector<float> color = {float(model_color[0]), float(model_color[1]), float(model_color[2]), float(model_color[3])};
|
||||
|
||||
paint(vertices, indices, color, line_mesh);
|
||||
|
|
|
@ -27,7 +27,7 @@ void LineEndNode::setSize(double size)
|
|||
}
|
||||
}
|
||||
|
||||
void LineEndNode::createOrUpdateGeometry(SceneInfo* sceneInfo)
|
||||
void LineEndNode::createOrUpdateGeometry(SceneInfo*)
|
||||
{
|
||||
if (!mContentNode)
|
||||
{
|
||||
|
|
|
@ -63,7 +63,7 @@ double TextNode::getContentWidth(SceneInfo* sceneInfo)
|
|||
return mContentWidth;
|
||||
}
|
||||
|
||||
double TextNode::getContentHeight(SceneInfo* sceneInfo)
|
||||
double TextNode::getContentHeight(SceneInfo*)
|
||||
{
|
||||
if (mContentHeight == 1.0)
|
||||
{
|
||||
|
|
|
@ -126,8 +126,8 @@ void SvgNode::onCircle(XmlElement* element, std::unique_ptr<GeometryNode>& node)
|
|||
{
|
||||
const auto transform = svg_circle->getTransform();
|
||||
loc.move(transform.getLocation().getX(), transform.getLocation().getY());
|
||||
radius *= transform.getScaleX();
|
||||
minor_radius *= transform.getScaleY();
|
||||
radius *= transform.getScale().mX;
|
||||
minor_radius *= transform.getScale().mY;
|
||||
}
|
||||
|
||||
auto circle_node = std::make_unique<CircleNode>(loc, radius);
|
||||
|
|
|
@ -71,8 +71,8 @@ void SvgPainter::paintMesh(SvgDocument* document, SceneModel* model, bool showOu
|
|||
auto face_locs = face->getNodeLocations();
|
||||
for (const auto& loc : face_locs)
|
||||
{
|
||||
const auto x = loc.getX() * transform.getScaleX() + transform.getLocation().getX();
|
||||
const auto y = loc.getY() * transform.getScaleY() + transform.getLocation().getY();
|
||||
const auto x = loc.getX() * transform.getScale().mX + transform.getLocation().getX();
|
||||
const auto y = loc.getY() * transform.getScale().mY + transform.getLocation().getY();
|
||||
points[count] = { x, y };
|
||||
count++;
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ void SvgPainter::setStyle(SceneModel* model, SvgShapeElement* element) const
|
|||
element->setNoStroke();
|
||||
}
|
||||
|
||||
if (!transform.isDefaultTransform())
|
||||
if (!transform.isIdentityTransform())
|
||||
{
|
||||
element->addAttribute(toTransform(transform));
|
||||
}
|
||||
|
@ -249,7 +249,7 @@ void SvgPainter::paintText(SvgDocument* document, SceneText* text) const
|
|||
svg_text->setFontSize(text->getTextData().mFont.getSize());
|
||||
|
||||
const auto transform = text->getTransform();
|
||||
if (!transform.isDefaultTransform())
|
||||
if (!transform.isIdentityTransform())
|
||||
{
|
||||
svg_text->addAttribute(toTransform(transform));
|
||||
}
|
||||
|
@ -262,13 +262,13 @@ std::unique_ptr<XmlAttribute> SvgPainter::toTransform(const Transform& transform
|
|||
auto svg_transform = std::make_unique<XmlAttribute>("transform");
|
||||
|
||||
std::string ops;
|
||||
if (!transform.hasDefaultLocation())
|
||||
if (!transform.isIdentityTransform())
|
||||
{
|
||||
ops += "translate(" + std::to_string(transform.getLocation().getX()) + " " + std::to_string(transform.getLocation().getY()) + ") ";
|
||||
}
|
||||
if (!transform.hasDefaultScale())
|
||||
if (!transform.getScale().isIdentity())
|
||||
{
|
||||
ops += "scale(" + std::to_string(transform.getScaleX()) + " " + std::to_string(transform.getScaleY()) + ") ";
|
||||
ops += "scale(" + std::to_string(transform.getScale().mX) + " " + std::to_string(transform.getScale().mY) + ") ";
|
||||
}
|
||||
svg_transform->setValue(ops);
|
||||
|
||||
|
|
|
@ -53,7 +53,8 @@ Transform SvgShapeElement::getTransform() const
|
|||
else if (in_scale)
|
||||
{
|
||||
const auto loc = parsePoint(working_string, 1.0);
|
||||
transform.setScale(loc.getX(), loc.getY(), loc.getZ());
|
||||
Scale scale(loc.getX(), loc.getY(), loc.getZ());
|
||||
transform.setScale(scale);
|
||||
in_scale = false;
|
||||
}
|
||||
working_string.clear();
|
||||
|
|
|
@ -14,7 +14,7 @@ xcb_gcontext_t XcbTextInterface::GetFontGC(xcb_connection_t *connection,
|
|||
/* create graphics context */
|
||||
xcb_gcontext_t gc = xcb_generate_id(connection);
|
||||
uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT;
|
||||
auto fillColor = textElement->getFillColor().getAsUInt32();
|
||||
auto fillColor = textElement->getMaterial()->getFillColor().getAsUInt32();
|
||||
uint32_t value_list[3] = {screen->black_pixel, fillColor, font };
|
||||
|
||||
xcb_create_gc(connection, gc, window, mask, value_list);
|
||||
|
|
|
@ -4,6 +4,11 @@
|
|||
|
||||
#include "Plot.h"
|
||||
#include "PlotNode.h"
|
||||
#include "PlotSeriesNode.h"
|
||||
#include "PlotCaptionNode.h"
|
||||
#include "EquationNode.h"
|
||||
#include "TextNode.h"
|
||||
#include "LineNode.h"
|
||||
|
||||
TEST_CASE(TestPlotting, "[publishing]")
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue