示例#1
0
void Plotter::MouseMotion(View& view, int x, int y, int button_state)
{
    const int d[2] = {x-last_mouse_pos[0], y-last_mouse_pos[1]};
    const float is[2] = {rview.x.Size(), rview.y.Size() };
    const float df[2] = {is[0]*d[0]/(float)v.w, is[1]*d[1]/(float)v.h};

    // Update hover status (after potential resizing)
    ScreenToPlot(x, y, hover[0], hover[1]);

    if( button_state == MouseButtonLeft )
    {
        // Update selected range
        selection.x.max = hover[0];
        selection.y.max = hover[1];
    }else if(button_state == MouseButtonMiddle )
    {
        Special(view, InputSpecialScroll, df[0], df[1], 0.0f, 0.0f, 0.0f, 0.0f, button_state);
    }else if(button_state == MouseButtonRight )
    {
        const float c[2] = {
            track || trigger_edge ? last_track_val[0] : hover[0],
            hover[1]
        };

        const float scale[2] = {
            1.0f + (float)d[0] / (float)v.w,
            1.0f - (float)d[1] / (float)v.h,
        };
        ScaleView(scale[0], scale[1], c[0], c[1]);
    }

    last_mouse_pos[0] = x;
    last_mouse_pos[1] = y;
}
示例#2
0
void CSpectrumFrame::OnRButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	Dialog.m_pos=m_fPos;
	Dialog.DoModal();
	m_fPos=Dialog.m_pos;
	ScaleView();
	this->RedrawWindow();	
	CMDIChildWnd::OnRButtonUp(nFlags, point);
}
示例#3
0
void CSpectrumFrame::OnCoeffS() 
{
	// TODO: Add your command handler code here
	//Dialog.GetCoeff(m_fPos,m_fPredel);
	Dialog.m_pos=m_fPos;
	Dialog.DoModal();
	m_fPos=Dialog.m_pos;
	ScaleView();
	this->RedrawWindow();
	
}
示例#4
0
文件: post.cpp 项目: Gecode/gecode
  void
  dopost(Home home, Term* t, int n, FloatRelType frt, FloatVal c) {
    Limits::check(c,"Float::linear");

    for (int i=n; i--; )
      if (t[i].x.assigned()) {
        c -= t[i].a * t[i].x.val();
        t[i]=t[--n];
      }

    if ((c < Limits::min) || (c > Limits::max))
      throw OutOfLimits("Float::linear");

    /*
     * Join coefficients for aliased variables:
     *
     */
    {
      // Group same variables
      TermLess tl;
      Support::quicksort<Term,TermLess>(t,n,tl);

      // Join adjacent variables
      int i = 0;
      int j = 0;
      while (i < n) {
        Limits::check(t[i].a,"Float::linear");
        FloatVal a = t[i].a;
        FloatView x = t[i].x;
        while ((++i < n) && same(t[i].x,x)) {
          a += t[i].a;
          Limits::check(a,"Float::linear");
        }
        if (a != 0.0) {
          t[j].a = a; t[j].x = x; j++;
        }
      }
      n = j;
    }

    Term *t_p, *t_n;
    int n_p, n_n;

    /*
     * Partition into positive/negative coefficents
     *
     */
    if (n > 0) {
      int i = 0;
      int j = n-1;
      while (true) {
        while ((t[j].a < 0) && (--j >= 0)) ;
        while ((t[i].a > 0) && (++i <  n)) ;
        if (j <= i) break;
        std::swap(t[i],t[j]);
      }
      t_p = t;     n_p = i;
      t_n = t+n_p; n_n = n-n_p;
    } else {
      t_p = t; n_p = 0;
      t_n = t; n_n = 0;
    }

    /*
     * Make all coefficients positive
     *
     */
    for (int i=n_n; i--; )
      t_n[i].a = -t_n[i].a;

    if (frt == FRT_GQ) {
      frt = FRT_LQ;
      std::swap(n_p,n_n); std::swap(t_p,t_n); c = -c;
    }

    if (n == 0) {
      switch (frt) {
      case FRT_EQ: if (!c.in(0.0)) home.fail(); break;
      case FRT_LQ: if (c.max() < 0.0) home.fail(); break;
      default: GECODE_NEVER;
      }
      return;
    }

    /*
     * Test for unit coefficients only
     *
     */
    bool is_unit = true;
    for (int i=n; i--; )
      if (t[i].a != 1.0) {
        is_unit = false;
        break;
      }

    if (is_unit) {
      // Unit coefficients
      ViewArray<FloatView> x(home,n_p);
      for (int i = n_p; i--; )
        x[i] = t_p[i].x;
      ViewArray<FloatView> y(home,n_n);
      for (int i = n_n; i--; )
        y[i] = t_n[i].x;
      post_nary<FloatView>(home,x,y,frt,c);
    } else {
      // Arbitrary coefficients
      ViewArray<ScaleView> x(home,n_p);
      for (int i = n_p; i--; )
        x[i] = ScaleView(t_p[i].a,t_p[i].x);
      ViewArray<ScaleView> y(home,n_n);
      for (int i = n_n; i--; )
        y[i] = ScaleView(t_n[i].a,t_n[i].x);
      post_nary<ScaleView>(home,x,y,frt,c);
    }
  }
示例#5
0
void Plotter::Special(View&, InputSpecial inType, float x, float y, float p1, float p2, float /*p3*/, float /*p4*/, int button_state)
{
    if(inType == InputSpecialScroll) {
        const float d[2] = {p1,-p2};
        const float is[2] = {rview.x.Size(),rview.y.Size() };
        const float df[2] = {is[0]*d[0]/(float)v.w, is[1]*d[1]/(float)v.h};

        ScrollView(-df[0], -df[1]);
    } else if(inType == InputSpecialZoom) {
        float scalex = 1.0;
        float scaley = 1.0;

#ifdef _OSX_
        if (button_state & KeyModifierCmd) {
#else
        if (button_state & KeyModifierCtrl) {
#endif
            scalex = 1-p1;
        }else{
            scaley = 1-p1;
        }

        const float c[2] = {
            track || trigger_edge ? last_track_val[0] : hover[0],
            hover[1]
        };

        ScaleView(scalex, scaley, c[0], c[1]);
    }

    // Update hover status (after potential resizing)
    ScreenToPlot( (int)x, (int)y, hover[0], hover[1]);
}

void Plotter::AddSeries(const std::string& x_expr, const std::string& y_expr,
    DrawingMode drawing_mode, Colour colour,
    const std::string& title, DataLog *log)
{
    if( !std::isfinite(colour.r) ) {
        colour = colour_wheel.GetUniqueColour();
    }
    plotseries.push_back( PlotSeries() );
    plotseries.back().CreatePlot(x_expr, y_expr, colour, (title == "$y") ? y_expr : title);
    plotseries.back().log = log;
    plotseries.back().drawing_mode = (GLenum)drawing_mode;
}

void Plotter::ClearSeries()
{
    plotseries.clear();
}

Marker& Plotter::AddMarker(Marker::Direction d, float value, Marker::Equality leg, Colour c )
{
    return AddMarker(Marker(d,value,leg,c));
}

Marker& Plotter::AddMarker( const Marker& marker )
{
    plotmarkers.push_back( marker );
    return plotmarkers.back();
}