PyObject *scriptVertexAdd(PyObject *self, PyObject *args) {
    PyObject *pyCoords=Py_None;
    if (!PyArg_ParseTuple(args, "|O", &pyCoords))
        return NULL;

    if (figureData.dim<0) {
        scriptThrowException("There is no space yet, use new or open");
        return NULL;
    }

    GLdouble coords[figureData.dim];
    if (!coordsFromPython(pyCoords, coords))
        return NULL;

    if (!safeCheckPos(coords, figureData.dim)) {
        scriptThrowException("Wrong position");
        return NULL;
    }

    int index=figureVertexAdd(coords);

    scriptEventsPerform(&scriptEventsModified);

    return Py_BuildValue("i", index);
}
Exemplo n.º 2
0
void consoleCmdRmap(char *key, int axis1, int axis2) {
	int code=hidCodeFromString(key);
	if (!code) {
		scriptThrowException("Wrong key shortcut");
		return;
	}

	if ((axis1<1) || (axis2<1) || (axis1==axis2)) {
		scriptThrowException("Wrong parameters");
		return;
	}
	animDestroyRot(hidMapRot(code, animCreateRot(axis1-1, axis2-1)));
}
Exemplo n.º 3
0
void consoleCmdWrite(char *path) {
	if (figureData.dim<0)
		scriptThrowException("Nothing opened");
	else {
		char *expr=scriptFigureToPythonExpr(&figureData);
		FILE *f=fopen(utilExpandPath(path), "w");
		if (!f) {
			scriptThrowException("File cannot be opened for writing");
			return;
		}
		fprintf(f, "import gf\ngf.figureOpen(%s)\n", expr);
		fclose(f);
		scriptEventsPerform(&scriptEventsWrite, path);
	}
}
Exemplo n.º 4
0
void consoleCmdRotate(int axis1, int axis2, double angle) {
	if ((axis1<1) || (axis2<1) || (axis1>figureData.dim) || (axis2>figureData.dim) || (axis1==axis2)) {
		scriptThrowException("Wrong parameters");
		return;
	}
	figureRotate(axis1-1, axis2-1, angle);
}
Exemplo n.º 5
0
void consoleCmdUnmap(char *key) {
	int code=hidCodeFromString(key);
	if (!code) {
		scriptThrowException("Wrong key shortcut");
		return;
	}
	hidMap(code, 0);
}
Exemplo n.º 6
0
void consoleCmdNew(int dim) {
	if ((dim<0) || (dim>safeMaxDim)) {
		scriptThrowException("Wrong parameters");
		return;
	}
	consoleCmdVertexDeselect();
	figureNew(dim);
	drawerSetDim(dim);
	scriptEventsPerform(&scriptEventsNew);
}
Exemplo n.º 7
0
void consoleCmdMap(char *key, char *cmd_or_expr) {
	int code=hidCodeFromString(key);
	if (!code) {
		scriptThrowException("Wrong key shortcut");
		return;
	}
	char *expr=consoleTranslToScriptExpr(cmd_or_expr);
	if (!expr)
		expr=cmd_or_expr;
	hidMap(code, expr);
}
PyObject *scriptVertexGetPos(PyObject *self, PyObject *args) {
    int index;
    if (!PyArg_ParseTuple(args, "i", &index))
        return NULL;

    if ((figureData.dim<0) || (index<0) || (index>=figureData.count[0])) {
        scriptThrowException("Out of bounds");
        return NULL;
    }

    return coordsToPython(figureData.vertices[index]);
}
PyObject *scriptVertexSetPos(PyObject *self, PyObject *args) {
    PyObject *pyCoords;
    int index;
    if (!PyArg_ParseTuple(args, "iO", &index, &pyCoords))
        return NULL;

    if ((figureData.dim<0) || (index<0) || (index>=figureData.count[0])) {
        scriptThrowException("Out of bounds");
        return NULL;
    }

    GLdouble coords[figureData.dim];
    if (!coordsFromPython(pyCoords, coords))
        return NULL;

    if (!safeCheckPos(coords, figureData.dim)) {
        scriptThrowException("Wrong position");
        return NULL;
    }

    figureVertexMove(index, coords);
    scriptEventsPerform(&scriptEventsModified);
    return Py_None;
}
Exemplo n.º 10
0
PyObject *scriptFigureConvexHullUpdate(PyObject *self, PyObject *args) {
	PyObject *pyFigure;
	if (!PyArg_ParseTuple(args, "O", &pyFigure))
		return NULL;

	struct figureData *figure=figureFromPython(pyFigure);
	if (!figure) {
		return NULL;
	}
	if (!convexUpdateHullAtOnce(figure)) {
		scriptThrowException("Loop detected while generating convex hull");
	}

	return figureToPython(figure);
}
Exemplo n.º 11
0
PyObject *scriptVertexRm(PyObject *self, PyObject *args) {
    int index;
    if (!PyArg_ParseTuple(args, "i", &index))
        return NULL;

    if ((figureData.dim<0) || (index<0) || (index>=figureData.count[0])) {
        scriptThrowException("Out of bounds");
        return NULL;
    }

    figureVertexRm(index);

    scriptEventsPerform(&scriptEventsModified);

    return Py_None;
}
Exemplo n.º 12
0
bool coordsFromPython(PyObject *pyCoords, GLdouble *coords) {
    if (pyCoords==Py_None) {
        for (int i=0; i<figureData.dim; i++)
            coords[i]=0;
    } else {
        if ((PyTuple_Size(pyCoords)!=figureData.dim) || (PyErr_Occurred())) {
            scriptThrowException("Wrong coordinates");
            return false;
        }
        for (int j=0; j<figureData.dim; j++) {
            PyObject *value=PyTuple_GET_ITEM(pyCoords, j);
            coords[j]=PyFloat_AsDouble(value);
        }
    }
    return true;
}
Exemplo n.º 13
0
void consoleCmdHelp(char *name) {
	if (!consolePrintNamedBlock("help", name))
		scriptThrowException("Wrong name of help page");
}