Merge remote-tracking branch 'svn/trunk'

This commit is contained in:
jriegel 2012-01-17 08:49:32 +01:00
commit 3e645d54de
10 changed files with 145 additions and 10 deletions

View File

@ -40,6 +40,7 @@
#include "Stream.h"
#include "Swap.h"
#include "FileInfo.h"
#include <CXX/Objects.hxx>
using namespace Base;
@ -533,6 +534,58 @@ IODeviceIStreambuf::seekpos(std::streambuf::pos_type pos,
return seekoff(pos, std::ios_base::beg);
}
// ---------------------------------------------------------
PyStreambuf::PyStreambuf(PyObject* o) : inp(o)
{
setg (buffer+pbSize,
buffer+pbSize,
buffer+pbSize);
}
int PyStreambuf::underflow()
{
if (gptr() < egptr()) {
return *gptr();
}
int numPutback;
numPutback = gptr() - eback();
if (numPutback > pbSize) {
numPutback = pbSize;
}
memcpy (buffer+(pbSize-numPutback), gptr()-numPutback, numPutback);
int num=0;
for (int i=0; i<bufSize; i++) {
char c;
Py::Tuple arg(1);
arg.setItem(0, Py::Int(1));
Py::Callable meth(Py::Object(inp).getAttr("read"));
try {
Py::Char res(meth.apply(arg));
c = static_cast<std::string>(res)[0];
num++;
buffer[pbSize+i] = c;
if (c == '\n')
break;
}
catch (Py::Exception& e) {
e.clear();
if (num == 0)
return EOF;
break;
}
}
setg (buffer+(pbSize-numPutback),
buffer+pbSize,
buffer+pbSize+num);
return *gptr();
}
// ---------------------------------------------------------
Streambuf::Streambuf(const std::string& data)

View File

@ -35,6 +35,7 @@
class QByteArray;
class QIODevice;
class QBuffer;
typedef struct _object PyObject;
namespace Base {
@ -232,6 +233,21 @@ protected:
static const int bufSize = 1024; // size of the data buffer
char buffer[bufSize+pbSize]; // data buffer
};
class BaseExport PyStreambuf : public std::streambuf
{
public:
PyStreambuf(PyObject* o);
protected:
int underflow();
private:
static const int pbSize = 4;
static const int bufSize = 1024;
char buffer[bufSize+pbSize];
PyObject* inp;
};
class BaseExport Streambuf : public std::streambuf
{

View File

@ -504,26 +504,26 @@ void Command::applyCommandData(Action* action)
{
action->setText(QCoreApplication::translate(
this->className(), sMenuText, 0,
QCoreApplication::CodecForTr));
QCoreApplication::UnicodeUTF8));
action->setToolTip(QCoreApplication::translate(
this->className(), sToolTipText, 0,
QCoreApplication::CodecForTr));
QCoreApplication::UnicodeUTF8));
if (sStatusTip)
action->setStatusTip(QCoreApplication::translate(
this->className(), sStatusTip, 0,
QCoreApplication::CodecForTr));
QCoreApplication::UnicodeUTF8));
else
action->setStatusTip(QCoreApplication::translate(
this->className(), sToolTipText, 0,
QCoreApplication::CodecForTr));
QCoreApplication::UnicodeUTF8));
if (sWhatsThis)
action->setWhatsThis(QCoreApplication::translate(
this->className(), sWhatsThis, 0,
QCoreApplication::CodecForTr));
QCoreApplication::UnicodeUTF8));
else
action->setWhatsThis(QCoreApplication::translate(
this->className(), sToolTipText, 0,
QCoreApplication::CodecForTr));
QCoreApplication::UnicodeUTF8));
}
const char* Command::keySequenceToAccel(int sk) const

View File

@ -1064,9 +1064,9 @@ StdCmdViewRotateLeft::StdCmdViewRotateLeft()
{
sGroup = QT_TR_NOOP("Standard-View");
sMenuText = QT_TR_NOOP("Rotate Left");
sToolTipText = QT_TR_NOOP("Rotate the view by 90° counter-clockwise");
sToolTipText = QT_TR_NOOP("Rotate the view by 90\xc2\xb0 counter-clockwise");
sWhatsThis = "Std_ViewXX";
sStatusTip = QT_TR_NOOP("Rotate the view by 90° counter-clockwise");
sStatusTip = QT_TR_NOOP("Rotate the view by 90\xc2\xb0 counter-clockwise");
sPixmap = "view-rotate-left";
//sAccel = "Shift Left";
eType = Alter3DView;
@ -1088,9 +1088,9 @@ StdCmdViewRotateRight::StdCmdViewRotateRight()
{
sGroup = QT_TR_NOOP("Standard-View");
sMenuText = QT_TR_NOOP("Rotate Right");
sToolTipText = QT_TR_NOOP("Rotate the view by 90° clockwise");
sToolTipText = QT_TR_NOOP("Rotate the view by 90\xc2\xb0 clockwise");
sWhatsThis = "Std_ViewXX";
sStatusTip = QT_TR_NOOP("Rotate the view by 90° clockwise");
sStatusTip = QT_TR_NOOP("Rotate the view by 90\xc2\xb0 clockwise");
sPixmap = "view-rotate-right";
//sAccel = "Shift Right";
eType = Alter3DView;

View File

@ -49,6 +49,7 @@ short Revolution::mustExecute() const
{
if (Base.isTouched() ||
Axis.isTouched() ||
Angle.isTouched() ||
Source.isTouched())
return 1;
return 0;

View File

@ -609,6 +609,32 @@ void TopoShape::importBrep(const char *FileName)
}
}
void TopoShape::importBrep(std::istream& str)
{
try {
// read brep-file
BRep_Builder aBuilder;
TopoDS_Shape aShape;
#if OCC_HEX_VERSION >= 0x060300
Handle_Message_ProgressIndicator pi = new ProgressIndicator(100);
pi->NewScope(100, "Reading BREP file...");
pi->Show();
BRepTools::Read(aShape,str,aBuilder,pi);
pi->EndScope();
#else
BRepTools::Read(aShape,str,aBuilder);
#endif
this->_Shape = aShape;
}
catch (Standard_Failure) {
Handle(Standard_Failure) aFail = Standard_Failure::Caught();
throw Base::Exception(aFail->GetMessageString());
}
catch (const std::exception& e) {
throw Base::Exception(e.what());
}
}
void TopoShape::write(const char *FileName) const
{
Base::FileInfo File(FileName);

View File

@ -120,6 +120,7 @@ public:
void importIges(const char *FileName);
void importStep(const char *FileName);
void importBrep(const char *FileName);
void importBrep(std::istream&);
void exportIges(const char *FileName) const;
void exportStep(const char *FileName) const;
void exportBrep(const char *FileName) const;

View File

@ -48,6 +48,11 @@ Sub-elements such as vertices, edges or faces are accessible as:
<UserDocu>Export the content of this shape to an STL mesh file.</UserDocu>
</Documentation>
</Methode>
<Methode Name="importBrep">
<Documentation>
<UserDocu>Import the content to this shape of a string in BREP format.</UserDocu>
</Documentation>
</Methode>
<Methode Name="extrude">
<Documentation>
<UserDocu>Extrude the shape along a direction.</UserDocu>

View File

@ -311,6 +311,30 @@ PyObject* TopoShapePy::exportBrep(PyObject *args)
Py_Return;
}
PyObject* TopoShapePy::importBrep(PyObject *args)
{
PyObject* input;
if (!PyArg_ParseTuple(args, "O", &input))
//char* input;
//if (!PyArg_ParseTuple(args, "s", &input))
return NULL;
try {
// read brep
Base::PyStreambuf buf(input);
std::istream str(0);
str.rdbuf(&buf);
//std::stringstream str(input);
getTopoShapePtr()->importBrep(str);
}
catch (const Base::Exception& e) {
PyErr_SetString(PyExc_Exception,e.what());
return NULL;
}
Py_Return;
}
PyObject* TopoShapePy::exportStl(PyObject *args)
{
char* filename;

View File

@ -215,6 +215,15 @@ void CmdSketcherMapSketch::activated(int iMsg)
qApp->translate(className(),"You have to select a single face as support for a sketch!"));
return;
}
std::vector<App::DocumentObject*> input = part->getOutList();
if (std::find(input.begin(), input.end(), sel[index]) != input.end()) {
QMessageBox::warning(Gui::getMainWindow(),
qApp->translate(className(),"Cyclic dependency"),
qApp->translate(className(),"You cannot choose a support object depending on the selected sketch!"));
return;
}
// get the selected sub shape (a Face)
const Part::TopoShape &shape = part->Shape.getValue();
TopoDS_Shape sh = shape.getSubShape(sub[0].c_str());