void TaskDatumParameters::onSuperplacementChanged(double /*val*/, int idx) { Part::Datum* pcDatum = static_cast<Part::Datum*>(DatumView->getObject()); Base::Placement pl = pcDatum->superPlacement.getValue(); Base::Vector3d pos = pl.getPosition(); if (idx == 0) { pos.x = ui->superplacementX->value().getValueAs(Base::Quantity::MilliMetre); } if (idx == 1) { pos.y = ui->superplacementY->value().getValueAs(Base::Quantity::MilliMetre); } if (idx == 2) { pos.z = ui->superplacementZ->value().getValueAs(Base::Quantity::MilliMetre); } if (idx >= 0 && idx <= 2){ pl.setPosition(pos); } Base::Rotation rot = pl.getRotation(); double yaw, pitch, roll; rot.getYawPitchRoll(yaw, pitch, roll); if (idx == 3) { yaw = ui->superplacementYaw->value().getValueAs(Base::Quantity::Degree); } if (idx == 4) { pitch = ui->superplacementPitch->value().getValueAs(Base::Quantity::Degree); } if (idx == 5) { roll = ui->superplacementRoll->value().getValueAs(Base::Quantity::Degree); } if (idx >= 3 && idx <= 5){ rot.setYawPitchRoll(yaw,pitch,roll); pl.setRotation(rot); } pcDatum->superPlacement.setValue(pl); updatePreview(); }
/** * This method was added for backward-compatibility. In former versions * of Box we had the properties x,y,z and l,h,w which have changed to * Location -- as replacement for x,y and z and Length, Height and Width. */ void Box::Restore(Base::XMLReader &reader) { reader.readElement("Properties"); int Cnt = reader.getAttributeAsInteger("Count"); bool location_xyz = false; bool location_axis = false; bool distance_lhw = false; Base::Placement plm; App::PropertyDistance x,y,z; App::PropertyDistance l,w,h; App::PropertyVector Axis, Location; Axis.setValue(0.0f,0.0f,1.0f); for (int i=0 ;i<Cnt;i++) { reader.readElement("Property"); const char* PropName = reader.getAttribute("name"); const char* TypeName = reader.getAttribute("type"); App::Property* prop = getPropertyByName(PropName); if (!prop) { // in case this comes from an old document we must use the new properties if (strcmp(PropName, "l") == 0) { distance_lhw = true; prop = &l; } else if (strcmp(PropName, "w") == 0) { distance_lhw = true; prop = &h; // by mistake w was considered as height } else if (strcmp(PropName, "h") == 0) { distance_lhw = true; prop = &w; // by mistake h was considered as width } else if (strcmp(PropName, "x") == 0) { location_xyz = true; prop = &x; } else if (strcmp(PropName, "y") == 0) { location_xyz = true; prop = &y; } else if (strcmp(PropName, "z") == 0) { location_xyz = true; prop = &z; } else if (strcmp(PropName, "Axis") == 0) { location_axis = true; prop = &Axis; } else if (strcmp(PropName, "Location") == 0) { location_axis = true; prop = &Location; } } else if (strcmp(PropName, "Length") == 0 && strcmp(TypeName,"PropertyDistance") == 0) { distance_lhw = true; prop = &l; } else if (strcmp(PropName, "Height") == 0 && strcmp(TypeName,"PropertyDistance") == 0) { distance_lhw = true; prop = &h; } else if (strcmp(PropName, "Width") == 0 && strcmp(TypeName,"PropertyDistance") == 0) { distance_lhw = true; prop = &w; } // NOTE: We must also check the type of the current property because a subclass // of PropertyContainer might change the type of a property but not its name. // In this case we would force to read-in a wrong property type and the behaviour // would be undefined. std::string tn = TypeName; if (strcmp(TypeName,"PropertyDistance") == 0) // missing prefix App:: tn = std::string("App::") + tn; if (prop && strcmp(prop->getTypeId().getName(), tn.c_str()) == 0) prop->Restore(reader); reader.readEndElement("Property"); } if (distance_lhw) { this->Length.setValue(l.getValue()); this->Height.setValue(h.getValue()); this->Width.setValue(w.getValue()); } // for 0.7 releases or earlier if (location_xyz) { plm.setPosition(Base::Vector3d(x.getValue(),y.getValue(),z.getValue())); this->Placement.setValue(this->Placement.getValue() * plm); this->Shape.setStatus(App::Property::User1, true); // override the shape's location later on } // for 0.8 releases else if (location_axis) { Base::Vector3d d = Axis.getValue(); Base::Vector3d p = Location.getValue(); Base::Rotation rot(Base::Vector3d(0.0,0.0,1.0), Base::Vector3d(d.x,d.y,d.z)); plm.setRotation(rot); plm.setPosition(Base::Vector3d(p.x,p.y,p.z)); this->Placement.setValue(this->Placement.getValue() * plm); this->Shape.setStatus(App::Property::User1, true); // override the shape's location later on } reader.readEndElement("Properties"); }
Py::Object fromShape(const Py::Tuple& args) { PyObject *pcObj; if (!PyArg_ParseTuple(args.ptr(), "O", &pcObj)) throw Py::Exception(); TopoDS_Shape shape; try { if (PyObject_TypeCheck(pcObj, &(Part::TopoShapePy::Type))) { shape = static_cast<Part::TopoShapePy*>(pcObj)->getTopoShapePtr()->getShape(); } else { throw Py::TypeError("the given object is not a shape"); } if (!shape.IsNull()) { if (shape.ShapeType() == TopAbs_WIRE) { Path::Toolpath result; bool first = true; Base::Placement last; TopExp_Explorer ExpEdges (shape,TopAbs_EDGE); while (ExpEdges.More()) { const TopoDS_Edge& edge = TopoDS::Edge(ExpEdges.Current()); TopExp_Explorer ExpVerts(edge,TopAbs_VERTEX); bool vfirst = true; while (ExpVerts.More()) { const TopoDS_Vertex& vert = TopoDS::Vertex(ExpVerts.Current()); gp_Pnt pnt = BRep_Tool::Pnt(vert); Base::Placement tpl; tpl.setPosition(Base::Vector3d(pnt.X(),pnt.Y(),pnt.Z())); if (first) { // add first point as a G0 move Path::Command cmd; std::ostringstream ctxt; ctxt << "G0 X" << tpl.getPosition().x << " Y" << tpl.getPosition().y << " Z" << tpl.getPosition().z; cmd.setFromGCode(ctxt.str()); result.addCommand(cmd); first = false; vfirst = false; } else { if (vfirst) vfirst = false; else { Path::Command cmd; cmd.setFromPlacement(tpl); // write arc data if needed BRepAdaptor_Curve adapt(edge); if (adapt.GetType() == GeomAbs_Circle) { gp_Circ circ = adapt.Circle(); gp_Pnt c = circ.Location(); bool clockwise = false; gp_Dir n = circ.Axis().Direction(); if (n.Z() < 0) clockwise = true; Base::Vector3d center = Base::Vector3d(c.X(),c.Y(),c.Z()); // center coords must be relative to last point center -= last.getPosition(); cmd.setCenter(center,clockwise); } result.addCommand(cmd); } } ExpVerts.Next(); last = tpl; } ExpEdges.Next(); } return Py::asObject(new PathPy(new Path::Toolpath(result))); } else { throw Py::TypeError("the given shape must be a wire"); } } else { throw Py::TypeError("the given shape is empty"); } } catch (const Base::Exception& e) { throw Py::RuntimeError(e.what()); } return Py::None(); }
App::DocumentObjectExecReturn *FeatureShape::execute(void) { TopoDS_Shape shape = Shape.getValue(); if (!shape.IsNull()) { if (shape.ShapeType() == TopAbs_WIRE) { Path::Toolpath result; bool first = true; Base::Placement last; TopExp_Explorer ExpEdges (shape,TopAbs_EDGE); while (ExpEdges.More()) { const TopoDS_Edge& edge = TopoDS::Edge(ExpEdges.Current()); TopExp_Explorer ExpVerts(edge,TopAbs_VERTEX); bool vfirst = true; while (ExpVerts.More()) { const TopoDS_Vertex& vert = TopoDS::Vertex(ExpVerts.Current()); gp_Pnt pnt = BRep_Tool::Pnt(vert); Base::Placement tpl; tpl.setPosition(Base::Vector3d(pnt.X(),pnt.Y(),pnt.Z())); if (first) { // add first point as a G0 move Path::Command cmd; std::ostringstream ctxt; ctxt << "G0 X" << tpl.getPosition().x << " Y" << tpl.getPosition().y << " Z" << tpl.getPosition().z; cmd.setFromGCode(ctxt.str()); result.addCommand(cmd); first = false; vfirst = false; } else { if (vfirst) vfirst = false; else { Path::Command cmd; cmd.setFromPlacement(tpl); // write arc data if needed BRepAdaptor_Curve adapt(edge); if (adapt.GetType() == GeomAbs_Circle) { gp_Circ circ = adapt.Circle(); gp_Pnt c = circ.Location(); bool clockwise = false; gp_Dir n = circ.Axis().Direction(); if (n.Z() < 0) clockwise = true; Base::Vector3d center = Base::Vector3d(c.X(),c.Y(),c.Z()); // center coords must be relative to last point center -= last.getPosition(); cmd.setCenter(center,clockwise); } result.addCommand(cmd); } } ExpVerts.Next(); last = tpl; } ExpEdges.Next(); } Path.setValue(result); } } return App::DocumentObject::StdReturn; }