|
Last Update:
October,
2008
Getting Started with qcadlib
Brief introduction for developers who intend to use qcadlib either
for QCAD development or development of other CAD related
applications.
Compiling the Examples

The following examples come with all the necessary source-files and
project files to compile them.
Downloading the QCAD Libraries
Before you start, you need to download and compile the QCAD
libraries. The easiest way to do this is to
download the QCAD community edition
and compile it. This will automatically also build the libraries.
In the following sections I assume that you have successfully
downloaded and compiled the libraries into $HOME/qcad2
Installing the QCAD Libraries
The example applications need to be able to find the libraries
and header files which are currently in the lib and include
directories under $HOME/qcad2.
I recommend to install them into $HOME/local/lib and $HOME/local/include
which can be done automatically using the standard makefiles:
cd $HOME/qcad2/dxflib
make install
cd $HOME/qcad2/qcadlib
make install
cd $HOME/qcad2/qcadcmd
make install
cd $HOME/qcad2/qcadactions
make install
cd $HOME/qcad2/qcadquiqt
make install
# if available / needed:
cd $HOME/qcad2/qcadprof
make install
cd $HOME/qcad2/qcadscripting
make install
|
Now your system should be ready to compile the examples from
below:
> qmake example01.pro
> make
g++ -c -pipe -Wall -W -g -I/opt/qt/mkspecs/linux-g++ -I.
-I/home/andrew/local/include -I/opt/qt/include -I.moc/
-o .obj/main.o main.cpp
g++ -o example01 .obj/main.o -Wl,-rpath,/opt/qt/lib
-L/opt/qt/lib -L/usr/X11R6/lib -L/home/andrew/local/lib
-lqcad -lqcadguiqt -ldxf -lqcadguiqt -lqcad -ldxf -lqt
-lXext -lX11 -lm
|
..and run them:
> ./example01
Line: (10/20/0/50/100/0)
|
Example 1: Creating a Graphic

This simple example creates a graphic with one line in it.
#include "qcadlib/rs_graphic.h"
#include "qcadlib/rs_line.h"
/**
* Main.
*/
int main() {
// create a new empty graphic
RS_Graphic* graphic = new RS_Graphic();
// create a line from 10/20 to 50/100
RS_LineData data(RS_Vector(10.0, 20.0),
RS_Vector(50.0, 100.0));
RS_Line* line = new RS_Line(graphic, data);
// add the line to the graphic
graphic->addEntity(line);
// stream line information to stdout
std::cout << *line;
// delete the graphic (this deletes also the line in it)
delete graphic;
}
|
Download Sources
main.cpp |
example01.pro
Example 2: Creating a Graphic View

This simple example creates a graphicview to display the line from
example 1 in it.
#include "rs_graphicview.h"
#include "rs_graphic.h"
#include "rs_line.h"
#include "qg_graphicview.h"
#include <qapplication.h>
#include <qmainwindow.h>
/**
* Main.
*/
int main(int argc, char** argv) {
// create a new empty graphic
RS_Graphic* graphic = new RS_Graphic();
// create a line from 10/20 to 50/100
RS_LineData data(RS_Vector(10.0, 20.0),
RS_Vector(50.0, 100.0));
RS_Line* line = new RS_Line(graphic, data);
line->setPen(RS_Pen(RS_Color(255,0,0),
RS2::Width12, RS2::SolidLine));
// add the line to the graphic
graphic->addEntity(line);
// create the Qt application and main window
QApplication app(argc, argv);
// create a graphic view as a mini-application:
QG_GraphicView graphicView;
graphicView.setContainer(graphic);
graphicView.setCaption("QCAD - Example 2");
app.setMainWidget(&graphicView);
app.connect(&app, SIGNAL(lastWindowClosed()),
&app, SLOT(quit()));
graphicView.show();
return app.exec();
}
|
Download Sources
main.cpp |
example02.pro
|