Commit 88ddfe6d authored by Hans-Christian Ebke's avatar Hans-Christian Ebke
Browse files

Plugin-FilePolyLine: Added backwards compatible load/save for bezier and circle poly lines.


git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@17643 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 9bf2c65d
......@@ -16,13 +16,18 @@
#include <OpenFlipper/ACGHelper/DrawModeConverter.hh>
#include <ObjectTypes/PolyLine/PolyLineCircleData.hh>
#include <ObjectTypes/PolyLine/PolyLineBezierSplineData.hh>
#include <OpenFlipper/BasePlugin/RPCInterface.hh>
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
template <class PointT>
void loadPolyLine(ACG::PolyLineT<PointT>& _polyLine, const char* _filename)
void FilePolyLinePlugin::loadPolyLine(PolyLineObject* lineObject, const char* _filename)
{
PolyLine& _polyLine = *lineObject->line();
// clear old polyline
_polyLine.clear();
......@@ -38,15 +43,14 @@ void loadPolyLine(ACG::PolyLineT<PointT>& _polyLine, const char* _filename)
int num_points;
fin >> num_points;
// read points
for(int i=0; i<num_points; ++i)
{
typename PointT::value_type x,y,z;
typename PolyLine::Point::value_type x,y,z;
fin >> x;
fin >> y;
fin >> z;
PointT p(x,y,z);
PolyLine::Point p(x,y,z);
_polyLine.add_point(p);
}
......@@ -60,50 +64,79 @@ void loadPolyLine(ACG::PolyLineT<PointT>& _polyLine, const char* _filename)
fin >> token;
if(token == "VVHANDLES")
{
if(!_polyLine.vertex_vhandles_available()) _polyLine.request_vertex_vhandles();
for(unsigned int i=0; i<_polyLine.n_vertices(); ++i)
fin >> _polyLine.vertex_vhandle(i);
if(!_polyLine.vertex_vhandles_available()) _polyLine.request_vertex_vhandles();
for(unsigned int i=0; i<_polyLine.n_vertices(); ++i)
fin >> _polyLine.vertex_vhandle(i);
}
else if(token == "VEHANDLES")
{
if(!_polyLine.vertex_ehandles_available()) _polyLine.request_vertex_ehandles();
for(unsigned int i=0; i<_polyLine.n_vertices(); ++i)
fin >> _polyLine.vertex_ehandle(i);
if(!_polyLine.vertex_ehandles_available()) _polyLine.request_vertex_ehandles();
for(unsigned int i=0; i<_polyLine.n_vertices(); ++i)
fin >> _polyLine.vertex_ehandle(i);
}
else if(token == "VFHANDLES")
{
if(!_polyLine.vertex_fhandles_available()) _polyLine.request_vertex_fhandles();
for(unsigned int i=0; i<_polyLine.n_vertices(); ++i)
fin >> _polyLine.vertex_fhandle(i);
if(!_polyLine.vertex_fhandles_available()) _polyLine.request_vertex_fhandles();
for(unsigned int i=0; i<_polyLine.n_vertices(); ++i)
fin >> _polyLine.vertex_fhandle(i);
}
else if(token == "VNORMALS")
{
if(!_polyLine.vertex_normals_available()) _polyLine.request_vertex_normals();
for(unsigned int i=0; i<_polyLine.n_vertices(); ++i)
{
fin >> _polyLine.vertex_normal(i)[0];
fin >> _polyLine.vertex_normal(i)[1];
fin >> _polyLine.vertex_normal(i)[2];
}
if(!_polyLine.vertex_normals_available()) _polyLine.request_vertex_normals();
for(unsigned int i=0; i<_polyLine.n_vertices(); ++i)
{
fin >> _polyLine.vertex_normal(i)[0];
fin >> _polyLine.vertex_normal(i)[1];
fin >> _polyLine.vertex_normal(i)[2];
}
}
else if(token == "VBINORMALS")
{
if(!_polyLine.vertex_binormals_available()) _polyLine.request_vertex_binormals();
for(unsigned int i=0; i<_polyLine.n_vertices(); ++i)
{
fin >> _polyLine.vertex_binormal(i)[0];
fin >> _polyLine.vertex_binormal(i)[1];
fin >> _polyLine.vertex_binormal(i)[2];
}
if(!_polyLine.vertex_binormals_available()) _polyLine.request_vertex_binormals();
for(unsigned int i=0; i<_polyLine.n_vertices(); ++i)
{
fin >> _polyLine.vertex_binormal(i)[0];
fin >> _polyLine.vertex_binormal(i)[1];
fin >> _polyLine.vertex_binormal(i)[2];
}
}
else if(token == "CIRCLEDATA") {
ACG::Vec3d center, normal, main, side;
double rmain, rside;
fin >> center;
fin >> main;
fin >> rmain;
fin >> normal;
fin >> side;
fin >> rside;
PolyLineCircleData* circleData = new PolyLineCircleData(center,normal,main,side,rmain,rside,std::numeric_limits<unsigned int>::max());
lineObject->setObjectData(CIRCLE_DATA, circleData);
}
else if(token == "SPLINEDATA") {
PolyLineBezierSplineData* splineData = new PolyLineBezierSplineData(std::numeric_limits<unsigned int>::max());
unsigned int pointCount, handleCount;
fin >> pointCount;
PolyLineBezierSplineData::InterpolatePoint point;
for(unsigned int i = 0; i < pointCount; i++) {
fin >> point.normal;
fin >> point.position;
splineData->points_.push_back(point);
}
fin >> handleCount;
for(unsigned int i = 0; i < handleCount; i++) {
fin >> point.position;
splineData->handles_.push_back(point.position);
}
lineObject->setObjectData(BEZSPLINE_DATA, splineData);
}
else if(token != "") break; //eat up empty lines
}
fin.close();
}
template <class PointT>
void savePolyLine(ACG::PolyLineT<PointT>& _polyLine, const char* _filename)
void FilePolyLinePlugin::savePolyLine(PolyLineObject* lineObject, const char* _filename)
{
PolyLine& _polyLine = *lineObject->line();
std::ofstream fout(_filename, std::ios::out);
......@@ -121,14 +154,14 @@ void savePolyLine(ACG::PolyLineT<PointT>& _polyLine, const char* _filename)
for(unsigned int i=0; i< _polyLine.n_vertices(); ++i)
{
const PointT& current_point = _polyLine.point(i);
const PolyLine::Point& current_point = _polyLine.point(i);
fout << current_point[0] << " ";
fout << current_point[1] << " ";
fout << current_point[2] << std::endl;
}
// ###########################
// Write properties
// Write properties(unsigned int)CircleType
if(_polyLine.vertex_vhandles_available())
{
......@@ -156,7 +189,7 @@ void savePolyLine(ACG::PolyLineT<PointT>& _polyLine, const char* _filename)
fout << "VNORMALS" << std::endl;
for( unsigned int i=0; i<_polyLine.n_vertices(); ++i)
{
const PointT& current_vnormal = _polyLine.vertex_normal(i);
const PolyLine::Point& current_vnormal = _polyLine.vertex_normal(i);
fout << current_vnormal[0] << " ";
fout << current_vnormal[1] << " ";
fout << current_vnormal[2] << std::endl;
......@@ -168,13 +201,38 @@ void savePolyLine(ACG::PolyLineT<PointT>& _polyLine, const char* _filename)
fout << "VBINORMALS" << std::endl;
for( unsigned int i=0; i<_polyLine.n_vertices(); ++i)
{
const PointT& current_bnormal = _polyLine.vertex_binormal(i);
const PolyLine::Point& current_bnormal = _polyLine.vertex_binormal(i);
fout << current_bnormal[0] << " ";
fout << current_bnormal[1] << " ";
fout << current_bnormal[2] << std::endl;
}
}
PolyLineCircleData* circleData = dynamic_cast<PolyLineCircleData*>(lineObject->objectData(CIRCLE_DATA));
if(circleData) {
fout << "CIRCLEDATA" << std::endl;
fout << circleData->circleCenter_ << std::endl;
fout << circleData->circleMainAxis_ << std::endl;
fout << circleData->circleMainRadius_ << std::endl;
fout << circleData->circleNormal_ << std::endl;
fout << circleData->circleSideAxis_ << std::endl;
fout << circleData->circleSideRadius_ << std::endl;
}
PolyLineBezierSplineData* splineData = dynamic_cast<PolyLineBezierSplineData*>(lineObject->objectData(BEZSPLINE_DATA));
if(splineData) {
fout << "SPLINEDATA" << std::endl;
fout << (unsigned int)splineData->points_.size() << std::endl;
for(unsigned int i = 0; i < splineData->points_.size(); i++) {
fout << splineData->points_[i].normal << std::endl;
fout << splineData->points_[i].position << std::endl;
}
fout << (unsigned int)splineData->handles_.size() << std::endl;
for(unsigned int i = 0; i < splineData->handles_.size(); i++)
fout << splineData->handles_[i] << std::endl;
fout << std::endl;
}
fout.close();
}
......@@ -203,7 +261,7 @@ int FilePolyLinePlugin::loadObject(QString _filename)
PolyLineObject* pol(0);
if(PluginFunctions::getObject( id, pol))
{
loadPolyLine(*(pol->line()), _filename.toLatin1());
loadPolyLine(pol, _filename.toLatin1());
pol->setFromFileName(_filename);
......@@ -229,7 +287,7 @@ bool FilePolyLinePlugin::saveObject(int _id, QString _filename)
obj->setName(_filename.section(OpenFlipper::Options::dirSeparator(),-1));
obj->setPath(_filename.section(OpenFlipper::Options::dirSeparator(),0,-2) );
savePolyLine(*(pol->line()), _filename.toLatin1());
savePolyLine(pol, _filename.toLatin1());
}
}
......
......@@ -37,6 +37,10 @@ class FilePolyLinePlugin : public QObject, BaseInterface, FileInterface, LoadSav
void emptyObjectAdded( int _id );
//RPC Interface
void pluginExists(QString _pluginName, bool &_exists);
void functionExists(QString _pluginName, QString _functionName, bool &_exists);
private slots:
void fileOpened( int /*_id*/ ){};
......@@ -48,6 +52,9 @@ class FilePolyLinePlugin : public QObject, BaseInterface, FileInterface, LoadSav
void initializePlugin();
void loadPolyLine(PolyLineObject* lineObject, const char* _filename);
void savePolyLine(PolyLineObject* lineObject, const char* _filename);
public :
~FilePolyLinePlugin() {};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment