+ improve automatic grid resizing in the sketcher

+ make sketch axes always visible
+ remove redundant funtions 


git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5097 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
logari81 2011-11-07 21:45:13 +00:00
parent 751929c87b
commit 8c515c381b
5 changed files with 55 additions and 52 deletions

View File

@ -62,7 +62,8 @@ ViewProvider2DObject::ViewProvider2DObject()
ADD_PROPERTY_TYPE(ShowGrid,(false),"Grid",(App::PropertyType)(App::Prop_None),"Switch the grid on/off");
ADD_PROPERTY_TYPE(GridSize,(10),"Grid",(App::PropertyType)(App::Prop_None),"Gap size of the grid");
ADD_PROPERTY_TYPE(GridStyle,((long)0),"Grid",(App::PropertyType)(App::Prop_None),"Appearence style of the grid");
ADD_PROPERTY_TYPE(GridSnap,(false),"GridSnap",(App::PropertyType)(App::Prop_None),"Switch the grid snap on/off");
ADD_PROPERTY_TYPE(TightGrid,(true),"Grid",(App::PropertyType)(App::Prop_None),"Switch the tight grid mode on/off");
ADD_PROPERTY_TYPE(GridSnap,(false),"Grid",(App::PropertyType)(App::Prop_None),"Switch the grid snap on/off");
GridRoot = new SoSeparator();
GridRoot->ref();
@ -89,20 +90,30 @@ SoSeparator* ViewProvider2DObject::createGrid(void)
//double dy = 10 * GridSize.getValue();
// float Size = (MaxX-MinX > MaxY-MinY) ? MaxX-MinX : MaxY-MinY;
float Step = GridSize.getValue(); //pow(10,floor(log10(Size/5.0)));
float MiX = MinX - (MaxX-MinX)*0.5;
float MaX = MaxX + (MaxX-MinX)*0.5;
float MiY = MinY - (MaxY-MinY)*0.5;
float MaY = MaxY + (MaxY-MinY)*0.5;
float MiX, MaX, MiY, MaY;
if (TightGrid.getValue()) {
MiX = MinX - (MaxX-MinX)*0.2f;
MaX = MaxX + (MaxX-MinX)*0.2f;
MiY = MinY - (MaxY-MinY)*0.2f;
MaY = MaxY + (MaxY-MinY)*0.2f;
}
else {
MiX = -exp(ceil(log(std::abs(MinX))));
MiX = std::min(MiX,(float)-exp(ceil(log(std::abs(0.1f*MaxX)))));
MaX = exp(ceil(log(std::abs(MaxX))));
MaX = std::max(MaX,(float)exp(ceil(log(std::abs(0.1f*MinX)))));
MiY = -exp(ceil(log(std::abs(MinY))));
MiY = std::min(MiY,(float)-exp(ceil(log(std::abs(0.1f*MaxY)))));
MaY = exp(ceil(log(std::abs(MaxY))));
MaY = std::max(MaY,(float)exp(ceil(log(std::abs(0.1f*MinY)))));
}
//Round the values otherwise grid is not aligned with center
MiX = ceil(MiX / Step) * Step;
MiX = floor(MiX / Step) * Step;
MaX = ceil(MaX / Step) * Step;
MiY = ceil(MiY / Step) * Step;
MiY = floor(MiY / Step) * Step;
MaY = ceil(MaY / Step) * Step;
//float Step = 10.0;
double dz = 0.0; // carpet-grid separation
//int gridsize = 20; // grid size
double zGrid = 0.0; // carpet-grid separation
SoSeparator *parent = GridRoot;
GridRoot->removeAllChildren();
@ -115,10 +126,10 @@ SoSeparator* ViewProvider2DObject::createGrid(void)
parent->addChild(mycolor);
vts = new SoVertexProperty;
vts->vertex.set1Value(0, -0.5*dx, -1.5*dy, 0.5*dz);
vts->vertex.set1Value(1, -0.5*dx, -1.5*dy, -0.5*dz);
vts->vertex.set1Value(2, 0.5*dx, -1.5*dy, 0.5*dz);
vts->vertex.set1Value(3, 0.5*dx, -1.5*dy, -0.5*dz);
vts->vertex.set1Value(0, -0.5*dx, -1.5*dy, 0.5*zGrid);
vts->vertex.set1Value(1, -0.5*dx, -1.5*dy, -0.5*zGrid);
vts->vertex.set1Value(2, 0.5*dx, -1.5*dy, 0.5*zGrid);
vts->vertex.set1Value(3, 0.5*dx, -1.5*dy, -0.5*zGrid);
SoQuadMesh *carpet = new SoQuadMesh;
carpet->verticesPerColumn = 2;
@ -158,16 +169,16 @@ SoSeparator* ViewProvider2DObject::createGrid(void)
float i;
for (i=MiX; i<MaX; i+=Step) {
/*float h=-0.5*dx + float(i) / gridsize * dx;*/
vts->vertex.set1Value(vi++, i, MiY, dz);
vts->vertex.set1Value(vi++, i, MaY, dz);
vts->vertex.set1Value(vi++, i, MiY, zGrid);
vts->vertex.set1Value(vi++, i, MaY, zGrid);
grid->numVertices.set1Value(l++, 2);
}
// horizontal lines
for (i=MiY; i<MaY; i+=Step) {
//float v=-0.5*dy + float(i) / gridsize * dy;
vts->vertex.set1Value(vi++, MiX, i, dz );
vts->vertex.set1Value(vi++, MaX, i, dz );
vts->vertex.set1Value(vi++, MiX, i, zGrid);
vts->vertex.set1Value(vi++, MaX, i, zGrid);
grid->numVertices.set1Value(l++, 2);
}
parent->addChild(vts);
@ -204,12 +215,12 @@ void ViewProvider2DObject::onChanged(const App::Property* prop)
ViewProviderPart::onChanged(prop);
if (prop == &ShowGrid) {
if(ShowGrid.getValue())
if (ShowGrid.getValue())
createGrid();
else
GridRoot->removeAllChildren();
}
if ((prop == &GridSize) || (prop == &GridStyle)) {
if ((prop == &GridSize) || (prop == &GridStyle) || (prop == &TightGrid)) {
if (ShowGrid.getValue()) {
GridRoot->removeAllChildren();
createGrid();

View File

@ -56,8 +56,7 @@ public:
App::PropertyBool ShowGrid;
App::PropertyDistance GridSize;
App::PropertyEnumeration GridStyle;
/// Properties for Grid Snap
App::PropertyBool TightGrid;
App::PropertyBool GridSnap;
virtual void attach(App::DocumentObject *);

View File

@ -80,13 +80,14 @@ TaskSketcherGeneral::~TaskSketcherGeneral()
void TaskSketcherGeneral::setGridSize(const QString& val)
{
float gridSize = (float) Base::UnitsApi::translateUnit(val);
sketchView->setGridSize(gridSize);
if (gridSize > 0)
sketchView->GridSize.setValue(gridSize);
}
void TaskSketcherGeneral::toggleGridSnap(int state)
{
setGridSize(ui->comboBoxGridSize->currentText()); // Ensure consistency
sketchView->setGridSnap(state == Qt::Checked);
sketchView->GridSnap.setValue(state == Qt::Checked);
}
void TaskSketcherGeneral::toggleAutoconstraints(int state)

View File

@ -1650,18 +1650,22 @@ void ViewProviderSketch::draw(bool temp)
SbVec3f *pverts = edit->PointsCoordinate->point.startEditing();
// set cross coordinates
if(MinY > 0 || MaxY < 0)
edit->RootCrossSetV->numVertices.set1Value(0,0);
else
edit->RootCrossSetV->numVertices.set1Value(0,2);
if(MinX > 0 || MaxX < 0)
edit->RootCrossSetH->numVertices.set1Value(0,0);
else
edit->RootCrossSetH->numVertices.set1Value(0,2);
edit->RootCrossCoordinateV->point.set1Value(0,SbVec3f((float)MinX - (MaxX-MinX)*0.5,0.0,zCross));
edit->RootCrossCoordinateV->point.set1Value(1,SbVec3f((float)MaxX + (MaxX-MinX)*0.5,0.0,zCross));
edit->RootCrossCoordinateH->point.set1Value(0,SbVec3f(0.0f,(float)MinY - (MaxY-MinY)*0.5f,zCross));
edit->RootCrossCoordinateH->point.set1Value(1,SbVec3f(0.0f,(float)MaxY + (MaxY-MinY)*0.5f,zCross));
edit->RootCrossSetV->numVertices.set1Value(0,2);
edit->RootCrossSetH->numVertices.set1Value(0,2);
float MiX = -exp(ceil(log(std::abs(MinX))));
MiX = std::min(MiX,(float)-exp(ceil(log(std::abs(0.1f*MaxX)))));
float MaX = exp(ceil(log(std::abs(MaxX))));
MaX = std::max(MaX,(float)exp(ceil(log(std::abs(0.1f*MinX)))));
float MiY = -exp(ceil(log(std::abs(MinY))));
MiY = std::min(MiY,(float)-exp(ceil(log(std::abs(0.1f*MaxY)))));
float MaY = exp(ceil(log(std::abs(MaxY))));
MaY = std::max(MaY,(float)exp(ceil(log(std::abs(0.1f*MinY)))));
edit->RootCrossCoordinateV->point.set1Value(0,SbVec3f(MiX, 0.0f, zCross));
edit->RootCrossCoordinateV->point.set1Value(1,SbVec3f(MaX, 0.0f, zCross));
edit->RootCrossCoordinateH->point.set1Value(0,SbVec3f(0.0f, MiY, zCross));
edit->RootCrossCoordinateH->point.set1Value(1,SbVec3f(0.0f, MaY, zCross));
int i=0; // setting up the line set
for (std::vector<Base::Vector3d>::const_iterator it = Coords.begin(); it != Coords.end(); ++it,i++)
@ -2606,6 +2610,7 @@ bool ViewProviderSketch::setEdit(int ModNum)
this->hide(); // avoid that the wires interfere with the edit lines
ShowGrid.setValue(true);
TightGrid.setValue(false);
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View");
float transparency;
@ -2826,6 +2831,7 @@ void ViewProviderSketch::createEditInventorNodes(void)
void ViewProviderSketch::unsetEdit(int ModNum)
{
ShowGrid.setValue(false);
TightGrid.setValue(true);
edit->EditRoot->removeAllChildren();
pcRoot->removeChild(edit->EditRoot);
@ -2984,17 +2990,6 @@ int ViewProviderSketch::getPreselectConstraint(void) const
return -1;
}
void ViewProviderSketch::setGridSnap(bool status)
{
GridSnap.setValue(status);
}
void ViewProviderSketch::setGridSize(float size)
{
if (size > 0)
GridSize.setValue(size);
}
Sketcher::SketchObject *ViewProviderSketch::getSketchObject(void) const
{
return dynamic_cast<Sketcher::SketchObject *>(pcObject);

View File

@ -178,9 +178,6 @@ public:
/// signals if the sketch has been solved
boost::signal<void (int type, float time)> signalSolved;
void setGridSnap(bool status);
void setGridSize(float size);
protected:
virtual bool setEdit(int ModNum);
virtual void unsetEdit(int ModNum);