bool XMLFPParser::parseFuzzySet (const xml_node& node, LinguisticVariable* variable){ xml_node magnitude = node.child(LINGUISTIC_VARIABLE_SET_DEFINITION_TAG); float A = parsing::extractFloat(magnitude.child(LINGUISTIC_VARIABLE_SET_POINT_A_TAG).first_child().value()); float B = parsing::extractFloat(magnitude.child(LINGUISTIC_VARIABLE_SET_POINT_B_TAG).first_child().value()); float C = parsing::extractFloat(magnitude.child(LINGUISTIC_VARIABLE_SET_POINT_C_TAG).first_child().value()); float D =parsing::extractFloat(magnitude.child(LINGUISTIC_VARIABLE_SET_POINT_D_TAG).first_child().value()); LDEBUG << "Fuzzy Set:"<< node.child(LINGUISTIC_VARIABLE_SET_ID_TAG).first_child().value(); LDEBUG << " A "<< magnitude.child(LINGUISTIC_VARIABLE_SET_POINT_A_TAG).first_child().value(); LDEBUG << " B "<< magnitude.child(LINGUISTIC_VARIABLE_SET_POINT_B_TAG).first_child().value(); LDEBUG << " C "<< magnitude.child(LINGUISTIC_VARIABLE_SET_POINT_C_TAG).first_child().value(); LDEBUG << " D "<< magnitude.child(LINGUISTIC_VARIABLE_SET_POINT_D_TAG).first_child().value(); correctPoint(A,variable); correctPoint(B,variable); correctPoint(C,variable); correctPoint(D,variable); if (A == B && B == C && C == D) return variable->addSet(new SingletonFuzzySet(node.child(LINGUISTIC_VARIABLE_SET_ID_TAG).first_child().value(), A)); else if (B == C) return variable->addSet(new TriangularFuzzySet(node.child(LINGUISTIC_VARIABLE_SET_ID_TAG).first_child().value(), A, B, D)); else if (A == B && C == D) return variable->addSet(new RectangularFuzzySet(node.child(LINGUISTIC_VARIABLE_SET_ID_TAG).first_child().value(), A, D)); else return variable->addSet(new TrapezoidalFuzzySet(node.child(LINGUISTIC_VARIABLE_SET_ID_TAG).first_child().value(), A, B, C, D)); }
// get local topLeft of an element surrounded by its margin. // Vec2 MLPositioner::getElementPositionWithMargin(int elementIdx) { Vec2 stepsXY; switch (mGeometry) { case kHorizontal: stepsXY = Vec2(elementIdx, 0); break; case kVertical: stepsXY = Vec2(0, elementIdx); break; case kRectangle: default: int y = elementIdx/mElemsXY[0]; int x = elementIdx - y*mElemsXY[0]; stepsXY = Vec2(x, y); break; } return correctPoint (mElementsMargin + stepsXY*mElementStep); }
// get local topLeft of an element within its margin. // Vec2 MLPositioner::getElementPosition(int elementIdx) { Vec2 p = correctPoint(getElementPositionWithMargin(elementIdx) + mElementMarginSize / Vec2(2.f)); return p; }
void MLDrawing::paint(Graphics& g) { MLLookAndFeel* myLookAndFeel = (&(getRootViewResources(this).mLookAndFeel)); float fu = myLookAndFeel->getGridUnitSize(); if (isOpaque()) myLookAndFeel->drawBackground(g, this); // defaults float ft = 1.0f * fu / 64.; float arrowScale = fu / 48.; float dotRadius = fu / 24.; mLineColor = mDarkColor; g.setColour(mLineColor); // int w = getWidth(); // int h = getHeight(); /* // TEST TODO auto border / background? Path tbounds; const MLRect boundsRect ( getLocalBounds()); tbounds.addRectangle(boundsRect); g.setColour(Colours::blue.withAlpha(0.5f)); g.fillPath(tbounds); g.setColour(Colours::red); g.strokePath(tbounds, PathStrokeType(1.0f)); */ //debug() << "painting MLDrawing " << getWidgetName() << "\n"; //int c = 0; for(auto op : mOperations) { Path p; Vec2 p1, p2; //const MLDrawing::Operation& op = *it; //debug() << " painting op " << c++ << "\n"; for(int i=0; i<4; ++i) { assert(ml::within((int)op.args[i], 0, (int)mTransformedPoints.size())); } switch(op.type) { case drawLine: p1 = mTransformedPoints[(int)op.args[0]]; p2 = mTransformedPoints[(int)op.args[1]]; p.startNewSubPath(MLToJucePoint(correctPoint(p1))); p.lineTo(MLToJucePoint(correctPoint(p2))); g.strokePath(p, PathStrokeType(ft)); break; case drawLineArrowStart: case drawLineArrowEnd: p1 = mTransformedPoints[(int)op.args[0]]; p2 = mTransformedPoints[(int)op.args[1]]; p.startNewSubPath(MLToJucePoint(correctPoint(p1))); p.lineTo(MLToJucePoint(correctPoint(p2))); g.strokePath(p, PathStrokeType(ft)); drawArrowhead(g, p1, p2, arrowScale); break; case drawDot: p1 = mTransformedPoints[(int)op.args[0]]; // p.startNewSubPath(MLToJucePoint(correctPoint(p1))); { juce::Point<float> pc = MLToJucePoint(correctPoint(p1)); juce::Point<float> pr1 = pc + juce::Point<float>(dotRadius, 0); p.startNewSubPath(pr1); int s = 10; for(int i=0; i<s; ++i) { float omega = i*kMLTwoPi/(s - 1); juce::Point<float> pr = pc + juce::Point<float>(cos(omega)*dotRadius, sin(omega)*dotRadius); p.lineTo(pr); } p.lineTo(pr1); g.fillPath(p); } break; case drawLineArrowBoth: break; case setLineThickness: mLineThickness = op.args[0]; ft = mLineThickness * fu / 64.; break; case setLightColor: g.setColour(mLightColor); break; case setDarkColor: g.setColour(mDarkColor); break; } } }