void RDimAlignedData::recomputeDefinitionPoint( const RVector& oldExtPoint1, const RVector& oldExtPoint2, const RVector& newExtPoint1, const RVector& newExtPoint2) { RLine dLine(oldExtPoint1, oldExtPoint2); double d = dLine.getDistanceTo(definitionPoint, false); RS::Side s = dLine.getSideOfPoint(definitionPoint); double a = newExtPoint1.getAngleTo(newExtPoint2); if (s==RS::LeftHand) { a+=M_PI/2.0; } else { a-=M_PI/2.0; } RVector v = RVector::createPolar(d, a); RVector dp = newExtPoint1 + v; if (dp.isValid()) { definitionPoint = dp; } }
void Button::createTexture(void) { Kernel *kernel = Kernel::getInstance(); if ((_cTexture = kernel->getWidgetTexture(BUTTON)) != NULL) return; ColorRGBA colorBotao1(250, 250, 250, 255); ColorRGBA colorBotao2(210, 210, 210, 255); ColorRGBA colorOver(220, 220, 220, 100); ColorRGBA colorClick(colorOver[0] - 100, colorOver[1] - 100, colorOver[2] - 100, colorOver[3]); // create texture object _cTexture = new ComponentTexture(8, 16); kernel->setWidgetTexture(BUTTON, _cTexture); _cTexture->setTextureEnvMode(GL_MODULATE); // left up MatrixTemplate<ColorRGBA> lUp(3, 3, ColorRGBA(0,0,0,0)); Texture2D::drawPoint(lUp, Point(0,1), ColorRGBA(144,144,144,230)); Texture2D::drawPoint(lUp, Point(1,1), ColorRGBA(144,144,144,230)); Texture2D::drawPoint(lUp, Point(1,0), ColorRGBA(144,144,144,230)); Texture2D::drawPoint(lUp, Point(1,2), ColorRGBA(202,202,202,200)); Texture2D::drawPoint(lUp, Point(2,2), ColorRGBA(240,240,240,240)); Texture2D::drawPoint(lUp, Point(2,1), ColorRGBA(202,202,202,200)); _cTexture->addTexture(Point(0,0), lUp); // right up MatrixTemplate<ColorRGBA> rUp(3, 3, ColorRGBA(0,0,0,0)); Texture2D::drawPoint(rUp, Point(1, 1), ColorRGBA(144,144,144,230)); Texture2D::drawPoint(rUp, Point(1, 0), ColorRGBA(144,144,144,230)); Texture2D::drawPoint(rUp, Point(2, 1), ColorRGBA(144,144,144,230)); Texture2D::drawPoint(rUp, Point(1, 2), ColorRGBA(202,202,202,200)); Texture2D::drawPoint(rUp, Point(0, 2), ColorRGBA(240,240,240,240)); Texture2D::drawPoint(rUp, Point(0, 1), ColorRGBA(202,202,202,200)); _cTexture->addTexture(Point(0,3), rUp); // left down MatrixTemplate<ColorRGBA> lDown(3, 3, ColorRGBA(0,0,0,0)); Texture2D::drawPoint(lDown, Point(0,1), ColorRGBA(144,144,144,230)); Texture2D::drawPoint(lDown, Point(1,1), ColorRGBA(144,144,144,230)); Texture2D::drawPoint(lDown, Point(1,2), ColorRGBA(144,144,144,230)); Texture2D::drawPoint(lDown, Point(1,0), ColorRGBA(202,202,202,200)); Texture2D::drawPoint(lDown, Point(2,0), ColorRGBA(240,240,240,240)); Texture2D::drawPoint(lDown, Point(2,1), ColorRGBA(202,202,202,200)); _cTexture->addTexture(Point(0,6), lDown); // right down MatrixTemplate<ColorRGBA> rDown(3, 3, ColorRGBA(0,0,0,0)); Texture2D::drawPoint(rDown, Point(1,2), ColorRGBA(144,144,144,230)); Texture2D::drawPoint(rDown, Point(2,1), ColorRGBA(144,144,144,230)); Texture2D::drawPoint(rDown, Point(1,1), ColorRGBA(144,144,144,230)); Texture2D::drawPoint(rDown, Point(1,0), ColorRGBA(202,202,202,200)); Texture2D::drawPoint(rDown, Point(0,0), ColorRGBA(240,240,240,240)); Texture2D::drawPoint(rDown, Point(0,1), ColorRGBA(202,202,202,200)); _cTexture->addTexture(Point(0,9), rDown); // normal middle MatrixTemplate<ColorRGBA> nMiddle(1, 16, ColorRGBA(0,0,0,0)); for (int i = 0, j = 15; i < 8; i++, j--) { Texture2D::drawPoint(nMiddle, Point(0,i), colorBotao1 - i * 2); Texture2D::drawPoint(nMiddle, Point(0,j), colorBotao2 - i * 2); } _cTexture->addTexture(Point(3,0), nMiddle); // over middle MatrixTemplate<ColorRGBA> oMiddle(1, 1, ColorRGBA(0,0,0,0)); Texture2D::drawPoint(oMiddle, Point(0,0), colorOver); _cTexture->addTexture(Point(4,0), oMiddle); // click middle MatrixTemplate<ColorRGBA> cMiddle(1, 1, ColorRGBA(0,0,0,0)); Texture2D::drawPoint(cMiddle, Point(0,0), colorClick); _cTexture->addTexture(Point(5,0), cMiddle); // up line MatrixTemplate<ColorRGBA> uLine(1, 2, ColorRGBA(0,0,0,0)); Texture2D::drawPoint(uLine, Point(0,0), ColorRGBA(112,112,112,255)); Texture2D::drawPoint(uLine, Point(0,1), ColorRGBA(255,255,255,255)); _cTexture->addTexture(Point(6,0), uLine); // down line MatrixTemplate<ColorRGBA> dLine(1, 2, ColorRGBA(0,0,0,0)); Texture2D::drawPoint(dLine, Point(0,0), ColorRGBA(255,255,255,255)); Texture2D::drawPoint(dLine, Point(0,1), ColorRGBA(112,112,112,255)); _cTexture->addTexture(Point(7,0), dLine); // left line MatrixTemplate<ColorRGBA> lLine(2, 1, ColorRGBA(0,0,0,0)); Texture2D::drawPoint(lLine, Point(0,0), ColorRGBA(112,112,112,255)); Texture2D::drawPoint(lLine, Point(1,0), ColorRGBA(255,255,255,255)); _cTexture->addTexture(Point(6,2), lLine); // right line MatrixTemplate<ColorRGBA> rLine(2, 1, ColorRGBA(0,0,0,0)); Texture2D::drawPoint(rLine, Point(1,0), ColorRGBA(112,112,112,255)); Texture2D::drawPoint(rLine, Point(0,0), ColorRGBA(255,255,255,255)); _cTexture->addTexture(Point(6,3), rLine); // generate texture _cTexture->createTexture(); }
void RS_Line::draw(RS_Painter* painter, RS_GraphicView* view, double& patternOffset) { if (painter==NULL || view==NULL) { return; } //only draw the visible portion of line QVector<RS_Vector> endPoints(0); RS_Vector vpMin(view->toGraph(0,view->getHeight())); RS_Vector vpMax(view->toGraph(view->getWidth(),0)); QPolygonF visualBox(QRectF(vpMin.x,vpMin.y,vpMax.x-vpMin.x, vpMax.y-vpMin.y)); if( getStartpoint().isInWindowOrdered(vpMin, vpMax) ) endPoints<<getStartpoint(); if( getEndpoint().isInWindowOrdered(vpMin, vpMax) ) endPoints<<getEndpoint(); if(endPoints.size()<2){ QVector<RS_Vector> vertex; for(unsigned short i=0;i<4;i++){ const QPointF& vp(visualBox.at(i)); vertex<<RS_Vector(vp.x(),vp.y()); } for(unsigned short i=0;i<4;i++){ RS_Line line(NULL,RS_LineData(vertex.at(i),vertex.at((i+1)%4))); auto&& vpIts=RS_Information::getIntersection(static_cast<RS_Entity*>(this), &line, true); if( vpIts.size()==0) continue; endPoints<<vpIts.get(0); } } if(endPoints.size()<2) return; if( (endPoints[0] - getStartpoint()).squared() > (endPoints[1] - getStartpoint()).squared() ) std::swap(endPoints[0],endPoints[1]); RS_Vector pStart(view->toGui(endPoints.at(0))); RS_Vector pEnd(view->toGui(endPoints.at(1))); // std::cout<<"draw line: "<<pStart<<" to "<<pEnd<<std::endl; RS_Vector direction=pEnd-pStart; if(isHelpLayer(true) && direction.squared() > RS_TOLERANCE){ //extend line on a help layer to fill the whole view RS_Vector lb(0,0); RS_Vector rt(view->getWidth(),view->getHeight()); QList<RS_Vector> rect; rect<<lb<<RS_Vector(rt.x,lb.y); rect<<rt<<RS_Vector(lb.x,rt.y); rect<<lb; RS_VectorSolutions sol; RS_Line dLine(pStart,pEnd); for(int i=0;i<4;i++){ RS_Line bLine(rect.at(i),rect.at(i+1)); RS_VectorSolutions sol2=RS_Information::getIntersection(&bLine, &dLine); if( sol2.getNumber()>0 && bLine.isPointOnEntity(sol2.get(0),RS_TOLERANCE)) { sol.push_back(sol2.get(0)); } } switch(sol.getNumber()){ case 2: pStart=sol.get(0); pEnd=sol.get(1); break; case 3: case 4: pStart=sol.get(0); pEnd=sol.get(2); break; default: return; } direction=pEnd-pStart; } double length=direction.magnitude(); patternOffset -= length; if (( !isSelected() && ( getPen().getLineType()==RS2::SolidLine || view->getDrawingMode()==RS2::ModePreview)) ) { //if length is too small, attempt to draw the line, could be a potential bug painter->drawLine(pStart,pEnd); return; } // double styleFactor = getStyleFactor(view); // Pattern: RS_LineTypePattern* pat; if (isSelected()) { // styleFactor=1.; pat = &patternSelected; } else { pat = view->getPattern(getPen().getLineType()); } if (pat==NULL) { // patternOffset -= length; RS_DEBUG->print(RS_Debug::D_WARNING, "RS_Line::draw: Invalid line pattern"); painter->drawLine(pStart,pEnd); return; } // patternOffset = remainder(patternOffset - length-0.5*pat->totalLength,pat->totalLength)+0.5*pat->totalLength; if(length<=RS_TOLERANCE){ painter->drawLine(pStart,pEnd); return; //avoid division by zero } direction/=length; //cos(angle), sin(angle) // Pen to draw pattern is always solid: RS_Pen pen = painter->getPen(); pen.setLineType(RS2::SolidLine); painter->setPen(pen); // index counter int i; // pattern segment length: double patternSegmentLength = pat->totalLength; // create pattern: RS_Vector* dp=new RS_Vector[pat->num > 0?pat->num:0]; double* ds=new double[pat->num > 0?pat->num:0]; if (pat->num >0 ){ double dpmm=static_cast<RS_PainterQt*>(painter)->getDpmm(); for (i=0; i<pat->num; ++i) { // ds[j]=pat->pattern[i] * styleFactor; //fixme, styleFactor support needed ds[i]=dpmm*pat->pattern[i]; if( fabs(ds[i]) < 1. ) ds[i] = (ds[i]>=0.)?1.:-1.; dp[i] = direction*fabs(ds[i]); } }else { delete[] dp; delete[] ds; RS_DEBUG->print(RS_Debug::D_WARNING,"invalid line pattern for line, draw solid line instread"); painter->drawLine(view->toGui(getStartpoint()), view->toGui(getEndpoint())); return; } double total= remainder(patternOffset-0.5*patternSegmentLength,patternSegmentLength) -0.5*patternSegmentLength; // double total= patternOffset-patternSegmentLength; RS_Vector p1,p2,p3; RS_Vector curP(pStart+direction*total); double t2; for(int j=0;total<length;j=(j+1)%i) { // line segment (otherwise space segment) t2=total+fabs(ds[j]); p3=curP+dp[j]; if (ds[j]>0.0 && t2 > 0.0) { // drop the whole pattern segment line, for ds[i]<0: // trim end points of pattern segment line to line p1 =(total > -0.5)? curP:pStart; p2 =(t2<length+0.5)?p3:pEnd; painter->drawLine(p1,p2); } total=t2; curP=p3; } delete[] dp; delete[] ds; }
void RS_Line::draw(RS_Painter* painter, RS_GraphicView* view, double& patternOffset) { if (painter==NULL || view==NULL) { return; } //visible in grahic view if(isVisibleInWindow(view)==false) return; RS_Vector pStart(view->toGui(getStartpoint())); RS_Vector pEnd(view->toGui(getEndpoint())); // std::cout<<"draw line: "<<pStart<<" to "<<pEnd<<std::endl; RS_Vector direction=pEnd-pStart; if(isHelpLayer(true) && direction.squared() > RS_TOLERANCE){ //extend line on a help layer to fill the whole view RS_Vector lb(0,0); RS_Vector rt(view->getWidth(),view->getHeight()); QList<RS_Vector> rect; rect<<lb<<RS_Vector(rt.x,lb.y); rect<<rt<<RS_Vector(lb.x,rt.y); rect<<lb; RS_VectorSolutions sol; RS_Line dLine(pStart,pEnd); for(int i=0;i<4;i++){ RS_Line bLine(rect.at(i),rect.at(i+1)); RS_VectorSolutions sol2=RS_Information::getIntersection(&bLine, &dLine); if( sol2.getNumber()>0 && bLine.isPointOnEntity(sol2.get(0),RS_TOLERANCE)) { sol.push_back(sol2.get(0)); } } switch(sol.getNumber()){ case 2: pStart=sol.get(0); pEnd=sol.get(1); break; case 3: case 4: pStart=sol.get(0); pEnd=sol.get(2); break; default: return; } direction=pEnd-pStart; } double length=direction.magnitude(); patternOffset -= length; if (( !isSelected() && ( getPen().getLineType()==RS2::SolidLine || view->getDrawingMode()==RS2::ModePreview)) ) { //if length is too small, attempt to draw the line, could be a potential bug painter->drawLine(pStart,pEnd); return; } // double styleFactor = getStyleFactor(view); // Pattern: RS_LineTypePattern* pat; if (isSelected()) { // styleFactor=1.; pat = &patternSelected; } else { pat = view->getPattern(getPen().getLineType()); } if (pat==NULL) { // patternOffset -= length; RS_DEBUG->print(RS_Debug::D_WARNING, "RS_Line::draw: Invalid line pattern"); painter->drawLine(pStart,pEnd); return; } // patternOffset = remainder(patternOffset - length-0.5*pat->totalLength,pat->totalLength)+0.5*pat->totalLength; if(length<=RS_TOLERANCE){ painter->drawLine(pStart,pEnd); return; //avoid division by zero } direction/=length; //cos(angle), sin(angle) // Pen to draw pattern is always solid: RS_Pen pen = painter->getPen(); pen.setLineType(RS2::SolidLine); painter->setPen(pen); // index counter int i; // pattern segment length: double patternSegmentLength = pat->totalLength; // create pattern: RS_Vector* dp=new RS_Vector[pat->num > 0?pat->num:0]; double* ds=new double[pat->num > 0?pat->num:0]; if (pat->num >0 ){ for (i=0; i<pat->num; ++i) { // ds[j]=pat->pattern[i] * styleFactor; //fixme, styleFactor support needed ds[i]=pat->pattern[i] ; dp[i] = direction*fabs(ds[i]); } }else { delete[] dp; delete[] ds; RS_DEBUG->print(RS_Debug::D_WARNING,"invalid line pattern for line, draw solid line instread"); painter->drawLine(view->toGui(getStartpoint()), view->toGui(getEndpoint())); return; } double total= remainder(patternOffset-0.5*patternSegmentLength,patternSegmentLength) -0.5*patternSegmentLength; // double total= patternOffset-patternSegmentLength; RS_Vector p1,p2,p3; RS_Vector curP(pStart+direction*total); double t2; for(int j=0;total<length;j=(j+1)%i) { // line segment (otherwise space segment) t2=total+fabs(ds[j]); p3=curP+dp[j]; if (ds[j]>0.0 && t2 > 0.0) { // drop the whole pattern segment line, for ds[i]<0: // trim end points of pattern segment line to line p1 =(total > -0.5)? curP:pStart; p2 =(t2<length+0.5)?p3:pEnd; painter->drawLine(p1,p2); } total=t2; curP=p3; } delete[] dp; delete[] ds; }