Skip to content

Commit

Permalink
Merge pull request #10 from jevandezande/master
Browse files Browse the repository at this point in the history
Accumulated Quality of Life and Error Fixes
  • Loading branch information
jevandezande authored Aug 9, 2024
2 parents 78d36ba + c6ad4ab commit f68ab39
Show file tree
Hide file tree
Showing 34 changed files with 163 additions and 129 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Test

on:
pull_request: {}
push:
branches: master

jobs:
test:
strategy:
matrix:
python-version: ['3.12']
os: [ubuntu-latest]

name: Python ${{ matrix.os }} ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
sudo apt update
sudo apt install time -y
sudo apt install qtbase5-dev qt5-qmake libjpeg-dev libpng-dev libqt5svg5-dev libtiff-dev -y
- name: Compile
run: ./build.py
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,5 @@ win32

*._*

chemvp0.2.tgz
TODO.txt

# compilation directory
objdir/
obj/
build/
4 changes: 1 addition & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ source is pretty simple.

1. Download and install Qt5 and necessary libraries
- On Ubuntu,: `aptitude install qt5-default libjpeg-dev libpng-dev libqt5svg5-dev libtiff-dev`
2. Head into the compilation directory in the cheMVP source folder (e.g. `mkdir build; cd build`)
3. Type '../qmake_script'
4. Type 'make'
2. Type `./build.py`


WARRANTY
Expand Down
49 changes: 49 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env python3
import os
import sys
from glob import glob
from subprocess import check_call

filename = "cheMVP.pro"
N_PROCS = os.cpu_count()

os.makedirs("build", exist_ok=True)
os.chdir("build")

sections = {
"SOURCES": "cpp",
"HEADERS": "h",
"RESOURCES": "qrc",
}

out = "\n".join(
f"{section} = " + " \\ \n".join(glob(f"../src/*.{ext}"))
for section, ext in sections.items()
)

out += """
CONFIG += debug_and_release static
QT += svg printsupport
QMAKE_CXXFLAGS_DEBUG = " -O0 -g"
macx{
ICON = ../images/icon.icns
CONFIG += x86
LIBS += -llapack -lblas
QMAKE_INFO_PLIST = ../chemvp.plist
}
win32{
RC_FILE = ../images/icon.rc
CONFIG -= debug
QMAKE_CXXFLAGS_RELEASE -= -mthreads
QMAKE_LFLAGS_RELEASE -= -mthreads
}"""

with open(filename, "w") as f:
f.write(out)

qmake_flags = "-spec macx-g++" if len(sys.argv) > 1 and sys.argv[1] == "mac" else ""

check_call(f"qmake {qmake_flags} {filename}".split())
check_call(f"time nice make -j {N_PROCS}".split())
Binary file modified images/addarrow.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/addbond.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/addtext.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/boldtext.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/cursor_move.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/cursor_rotate.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/cursor_select.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/delete.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/dmg_background.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/exit.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/icon.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/italictext.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/open.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/redo.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/rotate.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/save.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/saveas.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/select.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/underlinetext.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/undo.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 0 additions & 35 deletions qmake_script

This file was deleted.

52 changes: 26 additions & 26 deletions src/angle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ void Angle::updatePosition()
double r1 = sqrt(dX1 * dX1 + dY1 * dY1 + dZ1 * dZ1);
double cosTheta1 = dZ1 / r1;
double sinTheta1 = sin(acos(cosTheta1));
double phi1 = (norm1 == 0.0 ? 0.0 : acos(dY1 / norm1));
if (dX1 < 0.0) {
phi1 = 2.0 * PI - phi1;
double phi1 = (norm1 < 1e-9 ? 0 : acos(dY1 / norm1));
if (dX1 < 0) {
phi1 = 2 * PI - phi1;
}
// The angle between bond 2 and the vertical
double dX3 = myEndAtom->pos().x() - myCenterAtom->pos().x();
Expand All @@ -72,9 +72,9 @@ void Angle::updatePosition()
double r3 = sqrt(dX3 * dX3 + dY3 * dY3 + dZ3 * dZ3);
double cosTheta3 = dZ3 / r3;
double sinTheta3 = sin(acos(cosTheta3));
double phi3 = (norm3 == 0.0 ? 0.0 : acos(dY3 / norm3));
if (dX3 < 0.0) {
phi3 = 2.0 * PI - phi3;
double phi3 = (norm3 < 1e-9 ? 0 : acos(dY3 / norm3));
if (dX3 < 0) {
phi3 = 2 * PI - phi3;
}

double radius = myCenterAtom->effectiveRadius() + 0.2 * _info->scaleFactor();
Expand All @@ -92,19 +92,19 @@ void Angle::updatePosition()
// The vectors from atom2 to the points startPos and endPos are normalized to radius by
// construction. The
// sum of them is the midpoint, but it must be renormalized to radius
double scale = radius / sqrt(pow(bond1Pos.x() + bond2Pos.x() - 2.0 * xRef, 2.0) +
pow(bond1Pos.y() + bond2Pos.y() - 2.0 * yRef, 2.0) +
pow(bond1Z + bond2Z - 2.0 * zRef, 2.0));
double scale = radius / sqrt(pow(bond1Pos.x() + bond2Pos.x() - 2 * xRef, 2) +
pow(bond1Pos.y() + bond2Pos.y() - 2 * yRef, 2) +
pow(bond1Z + bond2Z - 2 * zRef, 2));
// This is the midpoint on the arc from p1 to p3
double zMP = zRef + scale * (bond1Z + bond2Z - 2.0 * zRef);
QPointF MP(xRef + scale * (bond1Pos.x() + bond2Pos.x() - 2.0 * xRef),
yRef + scale * (bond1Pos.y() + bond2Pos.y() - 2.0 * yRef));
double zMP = zRef + scale * (bond1Z + bond2Z - 2 * zRef);
QPointF MP(xRef + scale * (bond1Pos.x() + bond2Pos.x() - 2 * xRef),
yRef + scale * (bond1Pos.y() + bond2Pos.y() - 2 * yRef));

// Time to account for the angle markers not touching the bonds
double fraction = atan(ANGLE_MARKER_OFFSET);
scale = radius / sqrt(pow(bond1Pos.x() - xRef + fraction * (bond2Pos.x() - xRef), 2.0) +
pow(bond1Pos.y() - yRef + fraction * (bond2Pos.y() - yRef), 2.0) +
pow(bond1Z - zRef + fraction * (bond2Z - zRef), 2.0));
scale = radius / sqrt(pow(bond1Pos.x() - xRef + fraction * (bond2Pos.x() - xRef), 2) +
pow(bond1Pos.y() - yRef + fraction * (bond2Pos.y() - yRef), 2) +
pow(bond1Z - zRef + fraction * (bond2Z - zRef), 2));
QPointF startPos(xRef + scale * (bond1Pos.x() - xRef + fraction * (bond2Pos.x() - xRef)),
yRef + scale * (bond1Pos.y() - yRef + fraction * (bond2Pos.y() - yRef)));
QPointF endPos(xRef + scale * (bond2Pos.x() - xRef + fraction * (bond1Pos.x() - xRef)),
Expand All @@ -113,23 +113,23 @@ void Angle::updatePosition()
double endZ = zRef + scale * (bond2Z - zRef + fraction * (bond1Z - zRef));

// Redefine this to be the normalization for the quarter and three-quarter point vectors
scale = radius / sqrt(pow(MP.x() + startPos.x() - 2.0 * xRef, 2.0) +
pow(MP.y() + startPos.y() - 2.0 * yRef, 2.0) +
pow(zMP + startZ - 2.0 * zRef, 2.0));
scale = radius / sqrt(pow(MP.x() + startPos.x() - 2 * xRef, 2) +
pow(MP.y() + startPos.y() - 2 * yRef, 2) +
pow(zMP + startZ - 2 * zRef, 2));

// This will be the quarter point along the arc
QPointF QP1(xRef + scale * (startPos.x() + MP.x() - 2.0 * xRef),
yRef + scale * (startPos.y() + MP.y() - 2.0 * yRef));
QPointF QP1(xRef + scale * (startPos.x() + MP.x() - 2 * xRef),
yRef + scale * (startPos.y() + MP.y() - 2 * yRef));
// This will be the three-quarter point along the arc
QPointF QP3(xRef + scale * (endPos.x() + MP.x() - 2.0 * xRef),
yRef + scale * (endPos.y() + MP.y() - 2.0 * yRef));
QPointF QP3(xRef + scale * (endPos.x() + MP.x() - 2 * xRef),
yRef + scale * (endPos.y() + MP.y() - 2 * yRef));
myMarker1->setZValue(startZ);
myMarker2->setZValue(endZ);

// This is the interpolation formula to force the curve through QP1
QPointF guidePoint1 = 2.0 * QP1 - 0.5 * (startPos + MP);
QPointF guidePoint1 = 2 * QP1 - (startPos + MP)/2;
// This is the interpolation formula to force the curve through QP3
QPointF guidePoint3 = 2.0 * QP3 - 0.5 * (endPos + MP);
QPointF guidePoint3 = 2 * QP3 - (endPos + MP)/2;

QPainterPath path1(startPos);
path1.quadTo(guidePoint1, MP);
Expand All @@ -144,9 +144,9 @@ void Angle::updatePosition()
if (myLabel != 0) {
QPointF labelPos;
labelPos.setX(xRef + myLabel->dX() +
1.5 * scale * (endPos.x() + startPos.x() - 2.0 * xRef));
1.5 * scale * (endPos.x() + startPos.x() - 2 * xRef));
labelPos.setY(yRef + myLabel->dY() +
1.5 * scale * (endPos.y() + startPos.y() - 2.0 * yRef));
1.5 * scale * (endPos.y() + startPos.y() - 2 * yRef));
myLabel->setPos(labelPos);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
bool Application::event(QEvent *event)
{
switch (event->type()) {
case QEvent::FileOpen:
return loadFile(static_cast<QFileOpenEvent *>(event)->file());
default:
return QApplication::event(event);
case QEvent::FileOpen:
return loadFile(static_cast<QFileOpenEvent *>(event)->file());
default:
return QApplication::event(event);
}
}

Expand Down
30 changes: 14 additions & 16 deletions src/arrow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ DragBox::DragBox(double x, double y, DrawingInfo *info, QGraphicsItem *parent)
setAcceptHoverEvents(true);
setZValue(1001.0);
double dimension = 0.1 * drawingInfo->scaleFactor();
setRect(-dimension / 2.0, -dimension / 2.0, dimension, dimension);
setRect(-dimension / 2, -dimension / 2, dimension, dimension);
setPos(myDX + drawingInfo->dX(), myDY + drawingInfo->dY());
}

Expand Down Expand Up @@ -44,8 +44,7 @@ void DragBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q
{
Q_UNUSED(option);
Q_UNUSED(widget);
if (!hoverOver)
{
if (!hoverOver) {
return;
}
myPen.setWidthF(0.001 * drawingInfo->scaleFactor());
Expand All @@ -59,12 +58,12 @@ Arrow::Arrow(double x, double y, DrawingInfo *info, QGraphicsItem *parent)
{
setFlag(QGraphicsItem::ItemIsSelectable, true);
setAcceptHoverEvents(true);
setZValue(1000.0);
setZValue(1000);
myStartBox = new DragBox(x, y, drawingInfo);
myEndBox = new DragBox(x, y, drawingInfo);
setThickness(DEFAULT_ARROW_THICKNESS);
// So that the width of the line is correct when determining the shape
myPen.setWidth((int)(3.0 * effectiveWidth));
myPen.setWidth((int)(3 * effectiveWidth));
setPen(myPen);
}

Expand All @@ -77,7 +76,7 @@ void Arrow::updatePosition(double x, double y)

void Arrow::updatePosition()
{
double angle = (line().length() == 0.0 ? 0.0 : acos(line().dx() / line().length()));
double angle = (line().length() < 1e-9 ? 0 : acos(line().dx() / line().length()));
double arrowSize = 0.08 * drawingInfo->scaleFactor();
// Update the arrow position
myStartBox->setPos(drawingInfo->dX() + myStartBox->dX(), drawingInfo->dY() + myStartBox->dY());
Expand All @@ -87,23 +86,22 @@ void Arrow::updatePosition()
myEndBox->scenePos().x(),
myEndBox->scenePos().y()));

if (line().dy() >= 0)
{
angle = (PI * 2) - angle;
if (line().dy() >= 0) {
angle = (2 * PI) - angle;
}

QPointF arrowP1 =
line().p2() - QPointF(sin(angle + PI / 3.0) * arrowSize, cos(angle + PI / 3.0) * arrowSize);
QPointF arrowP2 = line().p2() - QPointF(sin(angle + PI - PI / 3.0) * arrowSize,
cos(angle + PI - PI / 3.0) * arrowSize);
line().p2() - QPointF(sin(angle + PI / 3) * arrowSize, cos(angle + PI / 3) * arrowSize);
QPointF arrowP2 = line().p2() - QPointF(sin(angle + PI - PI / 3) * arrowSize,
cos(angle + PI - PI / 3) * arrowSize);
arrowHead.clear();
arrowHead << line().p2() << arrowP1 << arrowP2;

// Stop the line at the butt of the arrowhead, not the tip
if (line().length() > arrowSize) {
setLine(QLineF(line().p1(),
line().p2() + QPointF(-cos(angle) * arrowSize * sqrt(3.0) / 2.0,
sin(angle) * arrowSize * sqrt(3.0) / 2.0)));
line().p2() + QPointF(-cos(angle) * arrowSize * sqrt(3) / 2,
sin(angle) * arrowSize * sqrt(3) / 2)));
}
// In case the scale factor changed, recompute the thickness
setThickness(myThickness);
Expand All @@ -113,7 +111,7 @@ void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWi
{
Q_UNUSED(option);
Q_UNUSED(widget);
myPen.setWidthF(hoverOver ? 2.0 * effectiveWidth : effectiveWidth);
myPen.setWidthF(hoverOver ? 2 * effectiveWidth : effectiveWidth);
myPen.setColor(Qt::black);
// Draw the line
painter->setPen(myPen);
Expand All @@ -124,7 +122,7 @@ void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWi
painter->setPen(myPen);
painter->drawPolygon(arrowHead);
if (isSelected()) {
myPen.setWidthF(hoverOver ? 10.0 * effectiveWidth : effectiveWidth);
myPen.setWidthF(hoverOver ? 10 * effectiveWidth : effectiveWidth);
myPen.setColor(SELECTED_COLOR);
painter->setPen(myPen);
painter->drawLine(line());
Expand Down
Loading

0 comments on commit f68ab39

Please sign in to comment.