Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@
/debian/libslvs1-dev/
/obj-*/
/*.slvs

# Intellij
.idea/
cmake-build-debug/
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,7 @@ if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebI
else()
message(STATUS "Benchmarking disabled in debug builds.")
endif()

# Dump project structure for static analysis
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

4 changes: 3 additions & 1 deletion bench/harness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
//
// Copyright 2016 whitequark
//-----------------------------------------------------------------------------
#include "solvespace.h"
#include "globals.h"
#include "util.h"
#include "namespace.h"

static bool RunBenchmark(std::function<void()> setupFn,
std::function<bool()> benchFn,
Expand Down
2 changes: 2 additions & 0 deletions include/slvs.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ typedef unsigned __int32 uint32_t;
#include <stdint.h>
#endif

#include <string.h>

typedef uint32_t Slvs_hParam;
typedef uint32_t Slvs_hEntity;
typedef uint32_t Slvs_hConstraint;
Expand Down
34 changes: 15 additions & 19 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,29 @@ set(HAVE_SPACEWARE ${SPACEWARE_FOUND})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
${CMAKE_CURRENT_BINARY_DIR}/config.h)

# platform utilities

if(WIN32)
set(util_SOURCES
platform/utilwin.cpp)
else()
set(util_SOURCES
platform/utilunix.cpp)
endif()
add_subdirectory(util)
add_subdirectory(pure_platform)


if(APPLE)
set(util_LIBRARIES
${APPKIT_LIBRARY})
endif()

# libslvs

set(libslvs_SOURCES
util.cpp
entity.cpp
expr.cpp
constraint.cpp
constrainteq.cpp
entity.cpp
expr.cpp
globals.cpp
system.cpp
platform/platform.cpp)
util.cpp
)

set(libslvs_HEADERS
globals.h
solvespace.h
platform/platform.h)
solvespaceui.h
)

add_library(slvs SHARED
${libslvs_SOURCES}
Expand All @@ -59,6 +53,8 @@ target_include_directories(slvs
PUBLIC ${CMAKE_SOURCE_DIR}/include)

target_link_libraries(slvs
util
pure_platform
${util_LIBRARIES})

set_target_properties(slvs PROPERTIES
Expand Down Expand Up @@ -148,7 +144,6 @@ set(solvespace_core_HEADERS
sketch.h
solvespace.h
ui.h
platform/platform.h
render/render.h
render/gl3shader.h
srf/surface.h)
Expand Down Expand Up @@ -190,7 +185,6 @@ set(solvespace_core_SOURCES
undoredo.cpp
util.cpp
view.cpp
platform/platform.cpp
platform/gui.cpp
render/render.cpp
render/render2d.cpp
Expand All @@ -213,6 +207,8 @@ add_library(solvespace-core STATIC

target_link_libraries(solvespace-core
dxfrw
util
pure_platform
${util_LIBRARIES}
${ZLIB_LIBRARY}
${PNG_LIBRARY}
Expand Down
6 changes: 5 additions & 1 deletion src/bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
//
// Copyright 2008-2013 Jonathan Westhues.
//-----------------------------------------------------------------------------
#include "solvespace.h"

#include <algorithm>
#include "sbsp.h"
#include "namespace.h"


SBsp2 *SBsp2::Alloc() { return (SBsp2 *)AllocTemporary(sizeof(SBsp2)); }
SBsp3 *SBsp3::Alloc() { return (SBsp3 *)AllocTemporary(sizeof(SBsp3)); }
Expand Down
6 changes: 5 additions & 1 deletion src/clipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
//
// Copyright 2008-2013 Jonathan Westhues.
//-----------------------------------------------------------------------------
#include "solvespace.h"

#include "solvespaceui.h"
#include "globals.h"
#include "util.h"
#include "namespace.h"

void SolveSpaceUI::Clipboard::Clear() {
c.Clear();
Expand Down
7 changes: 6 additions & 1 deletion src/confscreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
//
// Copyright 2008-2013 Jonathan Westhues.
//-----------------------------------------------------------------------------
#include "solvespace.h"
#include <math.h>
#include <cmath>
#include "ui.h"
#include "globals.h"
#include "util.h"
#include "namespace.h"

void TextWindow::ScreenChangeLightDirection(int link, uint32_t v) {
SS.TW.ShowEditControl(8, ssprintf("%.2f, %.2f, %.2f", CO(SS.lightDir[v])));
Expand Down
7 changes: 6 additions & 1 deletion src/constraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
//
// Copyright 2008-2013 Jonathan Westhues.
//-----------------------------------------------------------------------------
#include "solvespace.h"
#include "ss_util.h"
#include "constraint.h"
#include "ui.h"
#include "globals.h"
#include "util.h"
#include "namespace.h"

std::string Constraint::DescriptionString() const {
std::string s;
Expand Down
169 changes: 169 additions & 0 deletions src/constraint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
//
// Created by benjamin on 9/26/18.
//

#ifndef SOLVESPACE_CONSTRAINT_H
#define SOLVESPACE_CONSTRAINT_H

#include "handle.h"
#include "equation.h"
#include "render/canvas.h"

namespace SolveSpace {

// todo fix circular
enum class Command : uint32_t;

class ConstraintBase {
public:
int tag;
hConstraint h;

static const hConstraint NO_CONSTRAINT;

enum class Type : uint32_t {
POINTS_COINCIDENT = 20,
PT_PT_DISTANCE = 30,
PT_PLANE_DISTANCE = 31,
PT_LINE_DISTANCE = 32,
PT_FACE_DISTANCE = 33,
PROJ_PT_DISTANCE = 34,
PT_IN_PLANE = 41,
PT_ON_LINE = 42,
PT_ON_FACE = 43,
EQUAL_LENGTH_LINES = 50,
LENGTH_RATIO = 51,
EQ_LEN_PT_LINE_D = 52,
EQ_PT_LN_DISTANCES = 53,
EQUAL_ANGLE = 54,
EQUAL_LINE_ARC_LEN = 55,
LENGTH_DIFFERENCE = 56,
SYMMETRIC = 60,
SYMMETRIC_HORIZ = 61,
SYMMETRIC_VERT = 62,
SYMMETRIC_LINE = 63,
AT_MIDPOINT = 70,
HORIZONTAL = 80,
VERTICAL = 81,
DIAMETER = 90,
PT_ON_CIRCLE = 100,
SAME_ORIENTATION = 110,
ANGLE = 120,
PARALLEL = 121,
PERPENDICULAR = 122,
ARC_LINE_TANGENT = 123,
CUBIC_LINE_TANGENT = 124,
CURVE_CURVE_TANGENT = 125,
EQUAL_RADIUS = 130,
WHERE_DRAGGED = 200,

COMMENT = 1000
};

Type type;

hGroup group;
hEntity workplane;

// These are the parameters for the constraint.
double valA;
hParam valP;
hEntity ptA;
hEntity ptB;
hEntity entityA;
hEntity entityB;
hEntity entityC;
hEntity entityD;
bool other;
bool other2;

bool reference; // a ref dimension, that generates no eqs
std::string comment; // since comments are represented as constraints

bool HasLabel() const;

void Generate(IdList<Param, hParam> *param);

void GenerateEquations(IdList<Equation,hEquation> *entity,
bool forReference = false) const;
// Some helpers when generating symbolic constraint equations
void ModifyToSatisfy();
void AddEq(IdList<Equation,hEquation> *l, Expr *expr, int index) const;
void AddEq(IdList<Equation,hEquation> *l, const ExprVector &v, int baseIndex = 0) const;
static Expr *DirectionCosine(hEntity wrkpl, ExprVector ae, ExprVector be);
static Expr *Distance(hEntity workplane, hEntity pa, hEntity pb);
static Expr *PointLineDistance(hEntity workplane, hEntity pt, hEntity ln);
static Expr *PointPlaneDistance(ExprVector p, hEntity plane);
static ExprVector VectorsParallel3d(ExprVector a, ExprVector b, hParam p);
static ExprVector PointInThreeSpace(hEntity workplane, Expr *u, Expr *v);

void Clear() {}
};

class Constraint : public ConstraintBase {
public:
// See Entity::Entity().
Constraint() : ConstraintBase({}), disp() {}

// These define how the constraint is drawn on-screen.
struct {
Vector offset;
hStyle style;
} disp;

bool IsVisible() const;
bool IsStylable() const;
hStyle GetStyle() const;
bool HasLabel() const;
std::string Label() const;

enum class DrawAs { DEFAULT, HOVERED, SELECTED };
void Draw(DrawAs how, Canvas *canvas);
Vector GetLabelPos(const Camera &camera);
void GetReferencePoints(const Camera &camera, std::vector<Vector> *refs);

void DoLayout(DrawAs how, Canvas *canvas,
Vector *labelPos, std::vector<Vector> *refs);
void DoLine(Canvas *canvas, Canvas::hStroke hcs, Vector a, Vector b);
void DoStippledLine(Canvas *canvas, Canvas::hStroke hcs, Vector a, Vector b);
bool DoLineExtend(Canvas *canvas, Canvas::hStroke hcs,
Vector p0, Vector p1, Vector pt, double salient);
void DoArcForAngle(Canvas *canvas, Canvas::hStroke hcs,
Vector a0, Vector da, Vector b0, Vector db,
Vector offset, Vector *ref, bool trim);
void DoArrow(Canvas *canvas, Canvas::hStroke hcs,
Vector p, Vector dir, Vector n, double width, double angle, double da);
void DoLineWithArrows(Canvas *canvas, Canvas::hStroke hcs,
Vector ref, Vector a, Vector b, bool onlyOneExt);
int DoLineTrimmedAgainstBox(Canvas *canvas, Canvas::hStroke hcs,
Vector ref, Vector a, Vector b, bool extend,
Vector gr, Vector gu, double swidth, double sheight);
int DoLineTrimmedAgainstBox(Canvas *canvas, Canvas::hStroke hcs,
Vector ref, Vector a, Vector b, bool extend = true);
void DoLabel(Canvas *canvas, Canvas::hStroke hcs,
Vector ref, Vector *labelPos, Vector gr, Vector gu);
void DoProjectedPoint(Canvas *canvas, Canvas::hStroke hcs, Vector *p);
void DoProjectedPoint(Canvas *canvas, Canvas::hStroke hcs, Vector *p, Vector n, Vector o);

void DoEqualLenTicks(Canvas *canvas, Canvas::hStroke hcs,
Vector a, Vector b, Vector gn, Vector *refp);
void DoEqualRadiusTicks(Canvas *canvas, Canvas::hStroke hcs,
hEntity he, Vector *refp);

std::string DescriptionString() const;

static hConstraint AddConstraint(Constraint *c, bool rememberForUndo);
static hConstraint AddConstraint(Constraint *c);
static void MenuConstrain(Command id);
static void DeleteAllConstraintsFor(Constraint::Type type, hEntity entityA, hEntity ptA);

static hConstraint ConstrainCoincident(hEntity ptA, hEntity ptB);
static hConstraint Constrain(Constraint::Type type, hEntity ptA, hEntity ptB, hEntity entityA);
static hConstraint Constrain(Constraint::Type type, hEntity ptA, hEntity ptB,
hEntity entityA, hEntity entityB,
bool other, bool other2);
};

}

#endif //SOLVESPACE_CONSTRAINT_H
6 changes: 5 additions & 1 deletion src/constrainteq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
//
// Copyright 2008-2013 Jonathan Westhues.
//-----------------------------------------------------------------------------
#include "solvespace.h"

#include "constraint.h"
#include "entity.h"
#include "globals.h"
#include "namespace.h"

const hConstraint ConstraintBase::NO_CONSTRAINT = { 0 };

Expand Down
4 changes: 3 additions & 1 deletion src/describescreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
//
// Copyright 2008-2013 Jonathan Westhues.
//-----------------------------------------------------------------------------
#include "solvespace.h"
#include "ui.h"
#include "globals.h"
#include "namespace.h"

void TextWindow::ScreenUnselectAll(int link, uint32_t v) {
GraphicsWindow::MenuEdit(Command::UNSELECT_ALL);
Expand Down
6 changes: 5 additions & 1 deletion src/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
//
// Copyright 2008-2013 Jonathan Westhues.
//-----------------------------------------------------------------------------
#include "solvespace.h"
#include <chrono>
#include "ui.h"
#include "globals.h"
#include "util.h"
#include "namespace.h"

bool GraphicsWindow::Selection::Equals(Selection *b) {
if(entity.v != b->entity.v) return false;
Expand Down
5 changes: 4 additions & 1 deletion src/drawconstraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
//
// Copyright 2008-2013 Jonathan Westhues.
//-----------------------------------------------------------------------------
#include "solvespace.h"

#include "constraint.h"
#include "globals.h"
#include "namespace.h"

std::string Constraint::Label() const {
std::string result;
Expand Down
Loading