Exemple #1
0
void MainWindow::addRectangle() {
		BouncingRectangle* newRectangle = new BouncingRectangle(rand()%250, rand()%250, 20.0, 20.0, rand()%6, rand()%6);
		
		QBrush redBrush(Qt::red);
		QBrush blueBrush(Qt::blue);
		QBrush greenBrush(Qt::green);
		QBrush yellowBrush(Qt::yellow);
		
		int color = rand()%5;
		switch(color) {
			case 0:
			newRectangle->setBrush( redBrush );
			break;
			
			case 1:
			newRectangle->setBrush( blueBrush );
			break;
			
			case 2:
			newRectangle->setBrush( greenBrush );
			break;
			
			case 3:
			newRectangle->setBrush( yellowBrush );
			break;
		}
	
	rectangles.push_back(newRectangle);
	scene->addItem( newRectangle );
			
}
Exemple #2
0
void
MFCInstanceView::Draw(Graphics &dc, CRect &clipBox)
{
// !!!??? need to clip properly for short instances with long names
	Pen			blackPen(AlphaColor(250, rgb_black), 1);
	Pen			redPen(AlphaColor(250, rgb_red), 1);
	SolidBrush	blueBrush(AlphaColor(100, rgb_blue));
	SolidBrush	blackBrush(AlphaColor(100, rgb_black));

	CRect		clipBounds = bounds;
	if (clipBox.left > bounds.left) clipBounds.left = clipBox.left-1;
	if (clipBox.right < bounds.right) clipBounds.right = clipBox.right+1;

	cerr << "ondraw instance view " << clipBox.left << ", " << clipBox.right << endl;
	dc.FillRectangle(&blueBrush,
			bounds.left, bounds.top, bounds.right-bounds.left, bounds.bottom-bounds.top);
	dc.DrawRectangle(selected?&redPen:&blackPen,
			bounds.left, bounds.top, clipBounds.right-bounds.left, bounds.bottom-bounds.top);
	Font	labelFont(L"Arial", 8.0, FontStyleRegular, UnitPoint, NULL);
	wstring nm;
	const char *cp = instance->sym->uniqueName();
	while (*cp) { nm.push_back(*cp++); }
	float lbx = bounds.left+2;
#define LBLSEP 200
	if (clipBox.left > lbx) {
		int nld = clipBox.left - lbx;
		nld = nld/LBLSEP;
//		if (nld > 2) lbx += (nld-2)*LBLSEP;
	}
	PointF	p(lbx, clipBounds.top);
	do {
		dc.DrawString(nm.c_str(), -1, &labelFont, p, &blackBrush);
		p.X += LBLSEP;
	} while (p.X < clipBounds.right);
}
GraphicNetNode::GraphicNetNode(NetNode* node, QGraphicsItem* parent) :
	QGraphicsObject(parent)
{
	this->node = node;
	//addressText = node->getAddress().toString().c_str();
	//hostnameText = node->getName();
	addressText = new QGraphicsSimpleTextItem(node->getAddress().toString().c_str(), this);
	hostnameText = new QGraphicsSimpleTextItem(node->getName(), this);
	secondAddrsText = new QGraphicsSimpleTextItem(" ", this);

	QBrush blueBrush(Qt::blue);
	secondAddrsText->setBrush(blueBrush);

	QBrush brush(Qt::black);
	addressText->setBrush(brush);
	hostnameText->setBrush(brush);

	QPixmap pic(":/media/serverIcon");
	icon = new QGraphicsPixmapItem(pic, this);
	//icon->scale(0.75, 0.75);

	addressText->setVisible(true);
	hostnameText->setVisible(true);
	icon->setVisible(true);

	QFont textFont;
	textFont.setPixelSize(20);

	addressText->setFont(textFont);
	hostnameText->setFont(textFont);
	secondAddrsText->setFont(textFont);

	updateAddress();
}
Exemple #4
0
dialogSmithChart::dialogSmithChart(QWidget *parent) :
  QDialog(parent),
  ui(new Ui::dialogSmithChart)
{
  ui->setupUi(this);
  resize(430,400);

  scene = new QGraphicsScene(this);
  ui->graphicsView->setScene(scene);

  QBrush redBrush(Qt::red);
  QBrush blueBrush(Qt::blue);
  QPen blackPen(Qt::black);

  //ell = scene->addEllipse(10,10,100,100,blackPen,redBrush);
  QPainterPath* path = new QPainterPath();
 path->arcMoveTo(0,0,50,50,20);
 path->arcTo(0,0,50,50,20, 90);

 scene->addPath(*path);
 //ui->graphicsView->sc
  //h = 430; w = 400
//  centerX = 195;
//  CenterY = 191;

}
void TupColorPalette::setBaseColorsPanel()
{
#ifndef Q_OS_ANDROID
    QSize cellSize(50, 30);
#else
    QSize cellSize(70, 50);
#endif

    k->currentBaseColor = 0;
    QColor redColor(255, 0, 0);
    QBrush redBrush(redColor, k->brush.style());
    TupColorWidget *red = new TupColorWidget(0, redBrush, cellSize, false);
    red->selected();
    connect(red, SIGNAL(clicked(int)), this, SLOT(updateMatrix(int)));
    k->baseColors << red;

    QColor greenColor(0, 255, 0);
    QBrush greenBrush(greenColor, k->brush.style());
    TupColorWidget *green = new TupColorWidget(1, greenBrush, cellSize, false);
    connect(green, SIGNAL(clicked(int)), this, SLOT(updateMatrix(int)));
    k->baseColors << green;

    QColor blueColor(0, 0, 255);
    QBrush blueBrush(blueColor, k->brush.style());
    TupColorWidget *blue = new TupColorWidget(2, blueBrush, cellSize, false);
    connect(blue, SIGNAL(clicked(int)), this, SLOT(updateMatrix(int)));
    k->baseColors << blue;

    QColor whiteColor(255, 255, 255);
    QBrush whiteBrush(whiteColor, k->brush.style());
    TupColorWidget *white = new TupColorWidget(3, whiteBrush, cellSize, false);
    connect(white, SIGNAL(clicked(int)), this, SLOT(updateMatrix(int)));
    k->baseColors << white;

    QBoxLayout *bottomLayout = new QHBoxLayout;
    bottomLayout->setAlignment(Qt::AlignHCenter);
    bottomLayout->setContentsMargins(3, 3, 3, 3);

#ifndef Q_OS_ANDROID
    bottomLayout->setSpacing(10);
#else
    bottomLayout->setSpacing(25);
#endif

    bottomLayout->addWidget(red);
    bottomLayout->addWidget(green);
    bottomLayout->addWidget(blue);
    bottomLayout->addWidget(white);

    k->paletteGlobalLayout->addWidget(new TupSeparator(Qt::Horizontal));
    k->paletteGlobalLayout->addLayout(bottomLayout);
}
Exemple #6
0
void
MFCEditorItemView::Draw(Graphics &dc, CRect &clipBox)
{
// !!!??? need to clip properly for short instances with long names
	Pen			blackPen(Color(250, 0,0,0), 1);
	Pen			redPen(Color(250, 160, 10, 10), 1);
	SolidBrush	blueBrush(Color(100, 10, 10, 160));
	SolidBrush	blackBrush(Color(100, 0,0,0));

//	fprintf(stderr, "drawing instance view %d\n", bounds.right-bounds.left);
	dc.FillRectangle(&blueBrush, bounds.left, bounds.top, bounds.right-bounds.left, bounds.bottom-bounds.top);
	dc.DrawRectangle(selected?&redPen:&blackPen, bounds.left, bounds.top, bounds.right-bounds.left, bounds.bottom-bounds.top);
}
Exemple #7
0
/** Default Constructor*/
GraphicsWindow::GraphicsWindow()  {
    //We need a scene and a view to do graphics in QT
    scene = new QGraphicsScene();
    setScene(scene);
    setWindowTitle( "Programming Assignment #4: Math Puzzles");
    //view = new QGraphicsView( scene );

    //To fill a rectangle use a QBrush. To draw the border of a shape, use a QPen
    QBrush redBrush(Qt::red);
    QPen blackPen(Qt::black);
    QBrush blueBrush(Qt::blue);
    QBrush yellowBrush(Qt::yellow);
    QBrush greenBrush(Qt::green);

  	
}
Exemple #8
0
speckles::speckles(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::speckles)
{
    ui->setupUi(this);
    scene=new QGraphicsScene(this);

    ui->graphicsView->setScene(scene);
    QBrush redBrush(Qt::red);
    QBrush blueBrush(Qt::blue);
    QPen blackPen(Qt::black);
    blackPen.setWidth(6);
    ellipse=scene->addEllipse(10, 10, 100, 500, blackPen, redBrush);
    rectangle=scene->addRect(-10, -10, 100, 50, blackPen, blueBrush);
    qDebug()<<"The width of the scene is: "<<scene->width();
    qDebug()<<"The height of the scene is: "<<scene->height();
}
Exemple #9
0
wxBitmap BacklashGraph::CreateGraph(int bmpWidth, int bmpHeight)
{
    wxMemoryDC dc;
    wxBitmap bmp(bmpWidth, bmpHeight, -1);
    wxPen axisPen("BLACK", 3, wxCROSS_HATCH);
    wxPen redPen("RED", 3, wxSOLID);
    wxPen bluePen("BLUE", 3, wxSOLID);
    wxBrush redBrush("RED", wxSOLID);
    wxBrush blueBrush("BLUE", wxSOLID);
    //double fakeNorthPoints[] = 
    //{152.04, 164.77, 176.34, 188.5, 200.25, 212.36, 224.21, 236.89, 248.62, 260.25, 271.34, 283.54, 294.79, 307.56, 319.22, 330.87, 343.37, 355.75, 367.52, 379.7, 391.22, 403.89, 415.34, 427.09, 439.41, 450.36, 462.6};
    //double fakeSouthPoints[] = 
    //{474.84, 474.9, 464.01, 451.83, 438.08, 426, 414.68, 401.15, 390.39, 377.22, 366.17, 353.45, 340.75, 328.31, 316.93, 304.55, 292.42, 280.45, 269.03, 255.02, 243.76, 231.53, 219.43, 207.35, 195.22, 183.06, 169.47};
    //std::vector <double> northSteps(fakeNorthPoints, fakeNorthPoints + 27);
    //std::vector <double> southSteps(fakeSouthPoints, fakeSouthPoints + 27);
    std::vector <double> northSteps = m_BLT->GetNorthSteps();
    std::vector <double> southSteps = m_BLT->GetSouthSteps();

    double xScaleFactor;
    double yScaleFactor;
    int xOrigin;
    int yOrigin;
    int ptRadius;
    int graphWindowWidth;
    int graphWindowHeight;
    int numNorth;
    double northInc;
    int numSouth;

    // Find the max excursion from the origin in order to scale the points to fit the bitmap
    double maxDec = -9999.0;
    double minDec = 9999.0;
    for (std::vector<double>::const_iterator it = northSteps.begin(); it != northSteps.end(); ++it)
    {
        maxDec = wxMax(maxDec, *it);
        minDec = wxMin(minDec, *it);
    }

    for (std::vector<double>::const_iterator it = southSteps.begin(); it != southSteps.end(); ++it)
    {
        maxDec = wxMax(maxDec, *it);
        minDec = wxMin(minDec, *it);
    }

    graphWindowWidth = bmpWidth;
    graphWindowHeight = 0.7 * bmpHeight;
    yScaleFactor = (graphWindowHeight) / (maxDec - minDec + 1);
    xScaleFactor = (graphWindowWidth) / (northSteps.size() + southSteps.size());

    // Since we get mount coordinates, north steps will always be in ascending order
    numNorth = northSteps.size();
    northInc = (northSteps.at(numNorth - 1) - northSteps.at(0)) / numNorth;
    numSouth = southSteps.size();       // Should be same as numNorth but be careful

    dc.SelectObject(bmp);
    dc.SetBackground(*wxLIGHT_GREY_BRUSH);

    dc.SetFont(wxFont(12, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
    dc.Clear();

    // Bottom and top labels
    dc.SetTextForeground("BLUE");
    dc.DrawText(_("Ideal"), 0.7 * graphWindowWidth, bmpHeight - 25);
    dc.SetTextForeground("RED");
    dc.DrawText(_("Measured"), 0.2 * graphWindowWidth, bmpHeight - 25);
    dc.DrawText(_("North"), 0.1 * graphWindowWidth, 10);
    dc.DrawText(_("South"), 0.8 * graphWindowWidth, 10);
    // Draw the axes
    dc.SetPen(axisPen);
    xOrigin = graphWindowWidth / 2;
    yOrigin = graphWindowHeight + 40;           // Leave room at the top for labels and such
    dc.DrawLine(0, yOrigin, graphWindowWidth, yOrigin);    // x
    dc.DrawLine(xOrigin, yOrigin, xOrigin, 0);             // y

    // Draw the north steps
    dc.SetPen(redPen);
    dc.SetBrush(redBrush);
    ptRadius = 2;

    for (int i = 0; i < numNorth; i++)
    {
        wxPoint where = wxPoint(i * xScaleFactor, round(yOrigin - (northSteps.at(i) - minDec) * yScaleFactor));
        dc.DrawCircle(wxPoint(i * xScaleFactor, round(yOrigin - (northSteps.at(i) - minDec) * yScaleFactor)), ptRadius);
    }

    // Draw the south steps
    for (int i = 0; i < numSouth; i++)
    {
        dc.DrawCircle(wxPoint((i + numNorth) * xScaleFactor, round(yOrigin - (southSteps.at(i) - minDec) * yScaleFactor)), ptRadius);
    }

    // Now show an ideal south recovery line
    dc.SetPen(bluePen);
    dc.SetBrush(blueBrush);

    double peakSouth = southSteps.at(0);
    for (int i = 1; i <= numNorth; i++)
    {
        wxPoint where = wxPoint((i + numNorth)* xScaleFactor, round(yOrigin - (peakSouth - i * northInc - minDec) * yScaleFactor));
        dc.DrawCircle(where, ptRadius);
    }

    dc.SelectObject(wxNullBitmap);
    return bmp;

}
void BifurcationPlot::drawPlot() {
    /**
    *   Main drawing function for the plot classes.
    *
    *   The bifurcation plot is stored in a wxBitmap object so that we don't
    *   have to recalculate and draw every point every time we refresh the
    *   screen.  Since all of the ChaosPlots are buffered, this means that
    *   the Bifurcation drawing functions actually go through two buffers.
    *   This is not the most efficient way to do this, but it does allow us
    *   to use the functionality of the ChaosPlot subclass.
    *
    *   Steps for drawing:
    *
    *   Calculate X & Y axis values and size.
    *
    *   Store our current size.
    *
    *   Calls startDraw() to initalize the drawing DC. (Updates size)
    *
    *   Compare old size with current size to determine if it needs to redraw everything.
    *
    *   If so, draw axis on BufferedDC and copy them over to the MemoryDC,
    *   then redraw all points.
    *
    *   If not, collect points for up to 2 MDAC values and only draw 
    *   the new points on the MemoryDC.
    *
    *   Draw the MDAC reference line on the graph.
    *
    *   Finally, copy the MemoryDC over to the BufferedDC and draw it to the DC.
    *
    */
    float x_min, x_max;
    float y_min, y_max;
    wxString xaxis_title;
    wxMemoryDC bifMemDC;
    
    // Get information for the X axis
    if(ChaosSettings::BifXAxis == ChaosSettings::MDAC_VALUES) {
        xaxis_title = wxString(wxT("Mdac values"));
    } else {
        xaxis_title = wxString(wxT("Resistance (Ohms)"));
    }

    // Get scaling/label information for the Y axis
    if(ChaosSettings::YAxisLabels == ChaosSettings::Y_AXIS_VGND) {
        graph_subtitle = wxString::Format(wxT("Peaks (V) vs. %s"), xaxis_title.c_str());
        y_min = smallest_y_value*3.3/1024;
        y_max = largest_y_value*3.3/1024;
        x_min = smallest_x_value*3.3/1024;
        x_max = largest_x_value*3.3/1024;
    } else if(ChaosSettings::YAxisLabels == ChaosSettings::Y_AXIS_VBIAS) {
        graph_subtitle = wxString::Format(wxT("Peaks (V) vs. %s"), xaxis_title.c_str());
        y_min = smallest_y_value*3.3/1024 - 1.2;
        y_max = largest_y_value*3.3/1024 - 1.2;
        x_min = smallest_x_value*3.3/1024 - 1.2;
        x_max = largest_x_value*3.3/1024 - 1.2;
    } else {
        graph_subtitle = wxString::Format(wxT("Peaks (ADC) vs. %s"), xaxis_title.c_str());
        y_min = smallest_y_value;
        y_max = largest_y_value;
        x_min = smallest_x_value;
        x_max = largest_x_value;
    }
    
    // Store old size information for future comparison
    int old_width = width;
    int old_height = height;
    
    // Update size and draw background & titles
    startDraw();
    
    // Check and see if the size of the graph has changed
    // If it has, we need to redraw our cached image
    if(old_width != width || old_height != height) {
        ChaosSettings::BifRedraw = true;
    }
    
    // Do we need to redraw everything that we have cached?
    if(ChaosSettings::BifRedraw == true) {
        // Draw the Y axis on the buffered DC
        drawYAxis(y_min, y_max, (y_max-y_min)/4.0);
        
        // Draw the X axis on the buffered DC
        if(ChaosSettings::BifXAxis == ChaosSettings::MDAC_VALUES) { 
            drawXAxis(float(largest_x_value),
                  float(smallest_x_value),
                  -1*((largest_x_value-smallest_x_value)/4));
        } else {
            float min = libchaos_mdacToResistance(largest_x_value);
            float max = libchaos_mdacToResistance(smallest_x_value);
            drawXAxis(min, max, ((max-min)/4));
        }
        
        // If we aren't connected, then we're done
        if(device_connected == false) {
            endDraw();
            return;
        }

        // if we already have a cached image, delete it
        if(bifBmp)
            delete bifBmp;
            
        // Create a bitmap to cache our bifurcation drawing to
        bifBmp = new wxBitmap(width, height);
        
        // Select the bitmap to a memory DC so we can draw on it and initialize it with a background
        bifMemDC.SelectObject(*bifBmp);
        bifMemDC.SetBrush(dc->GetBackground());
        bifMemDC.SetPen(*wxTRANSPARENT_PEN);
        bifMemDC.DrawRectangle(0,0,width,height);
        
        // Copy what we have on the buffer so far (title, axis, labels) to the cache
        bifMemDC.Blit(0, 0, width, height, buffer, 0, 0);
    } else {
        // No need to redraw everything, just select the cache so we can draw more onto it
        bifMemDC.SelectObject(*bifBmp);
    }

    //Use blue pen
    wxPen bluePen(*wxBLUE, 1); // blue pen of width 1
    wxBrush blueBrush(*wxBLUE_BRUSH);
    bifMemDC.SetPen(bluePen);
    bifMemDC.SetBrush(blueBrush);

    int* peaks;
    int new_points;
    int step = (int)(float(graph_width) / float(ChaosSettings::BifStepsPerWindow));
    
    if(step == 0) step = 1;
    
    // If we are paused, don't collect new data points
    if(paused || ChaosSettings::Paused) {
        new_points = 0;
    } else {
        new_points = 2;
        libchaos_disableFFT();
    }


    // Draw points, collecting new data if necessary.
    int miss_mdac = -1;
    for(int i = 1; i < graph_width; i+=step) {
        int mdac_value = xToMdac(i);
        
        /* Since the user can technically zoom into areas slightly beyond
        our mdac limits, we have to ensure we have a correct value. */
        if (mdac_value > 4095) {
            mdac_value = 4095;
        } else if (mdac_value < 0) {
            mdac_value = 0;
        }
        
        bool cacheHit = libchaos_peaksCacheHit(mdac_value);

        if(!cacheHit) new_points--;
        if((ChaosSettings::BifRedraw && cacheHit) || (!cacheHit && new_points > 0)) {

            peaks = libchaos_getPeaks(mdac_value);
            if(cacheHit == false) {
                miss_mdac = mdac_value;
            }
            
            bifMemDC.SetPen(bluePen);
            for(int j = 0; j < ChaosSettings::PeaksPerMdac; j++) {
                int y = valueToY(peaks[j]);
                if(y < graph_height + top_gutter_size && y > top_gutter_size) {
                    drawPoint(&bifMemDC, valueToX(mdac_value), y);
                }
            }
        }
        
    }
    
    if( new_points > 0 ) libchaos_enableFFT();
    
    if(miss_mdac != -1) {
        device_mdac_value = miss_mdac;
    }
    
    // We're finished redrawing everything, so don't do it again unless we need to
    if(ChaosSettings::BifRedraw == true) {
        ChaosSettings::BifRedraw = false;
    }

    // Copy our cache onto the buffered DC
    // (It is redundant to use a MemoryDC and a BufferedDC, it may be more efficient
    // to not use the BufferedDC for the bifurcation)
    buffer->Blit(0,0, width, height, &bifMemDC, 0, 0);
    
    // Draw the line for the MDAC
    drawMdacLine(buffer);
    
    // Flush the buffer and output to the screen.
    endDraw();

}
twoChessBoard::twoChessBoard(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::twoChessBoard)
{

	// There are issues with this right now. Hardcoded integers are only used for testing on simulator, not actual phone.
    this->parent = parent;
    ui->setupUi(this);
    ui->widget->setGeometry(QRect(10,130,480,480));
    graphicsView = new QGraphicsView(ui->widget);
    scene = new QGraphicsScene(QRect(-240,-180,480,480));
    graphicsView->setGeometry(QRect(0,0,490,490));
    graphicsView->setScene(scene);
    select = 0;//used to check whether a piece is selected or not
    turn = 1;//used to check which players turn it is
    //the following are to check how many different kind of pieces are left in the board
    blackPawnsLeft = 8;
    whitePawnsLeft = 8;
    blackRooksLeft = 2;
    whiteRooksLeft = 2;
    blackKnightsLeft = 2;
    whiteKnightsLeft = 2;
    blackBishopsLeft = 2;
    whiteBishopsLeft = 2;
    blackQueenLeft = 1;
    whiteQueenLeft = 1;
    blackKingLeft = 1;
    whiteKingLeft = 1;

    // colors for pieces
    QBrush blackBrush(Qt::black);
    QBrush whiteBrush(Qt::white);
    QBrush greenBrush(Qt::green);
    QBrush redBrush(Qt::red);
    QBrush yellowBrush(Qt::yellow);
    QBrush blueBrush(Qt::blue);
    QBrush magentaBrush(Qt::magenta);
    QBrush grayBrush(Qt::gray);

    QBrush darkGreenBrush(Qt::darkGreen);
    QBrush darkRedBrush(Qt::darkRed);
    QBrush darkYellowBrush(Qt::darkYellow);
    QBrush darkBlueBrush(Qt::darkBlue);
    QBrush darkMagentaBrush(Qt::darkMagenta);
    QBrush darkGrayBrush(Qt::darkGray);

    QPen pen(Qt::transparent);
    pen.setWidth(0);


    // This loop generates the chessboard. Code was written by TA.
    for(int i=0;i<CHESSBOARD_SIZE;i++){

        chessboard[i].resize(CHESSBOARD_SIZE);
        for(int j = 0 ; j<CHESSBOARD_SIZE;j++){
            chessboard[i][j] = new QGraphicsRectItem(CHESSBOARD_GRID_SIZE*(j-CHESSBOARD_SIZE/2) , CHESSBOARD_GRID_SIZE*( -i+CHESSBOARD_SIZE/2) ,
                            CHESSBOARD_GRID_SIZE ,CHESSBOARD_GRID_SIZE);
            scene->addItem(chessboard[i][j]);
            chessboard[i][j]->setPen(pen);

            chessboard[i][j]->setBrush(((i+j)%2==0)?blackBrush:whiteBrush);

        }
    }

    graphicsView->show();
    qDebug("Initialized chessboard...");


    for(int i =0; i<8;i++)
    {
        for(int j=0;j<8;j++)
        {
            boardvalues[i][j] = 0;
        }
    }


    //initialising the board values
    for(int i = 0;i<8;i++)
    {
        //pawns
        boardvalues[1][i] = 1;
        boardvalues[6][i] = 7;
    }

    //rooks
    boardvalues[0][0] = 2;
    boardvalues[0][7] = 2;
    boardvalues[7][0] = 8;
    boardvalues[7][7] = 8;

    //knights
    boardvalues[0][1] = 3;
    boardvalues[0][6] = 3;
    boardvalues[7][1] =9;
    boardvalues[7][6] =9;

    //bishops
    boardvalues[0][2] = 4;
    boardvalues[0][5] = 4;
    boardvalues[7][2] =10;
    boardvalues[7][5] =10;

    //queen
    boardvalues[0][3] = 6;
    boardvalues[7][3] =12;

    //king
    boardvalues[0][4] = 5;
    boardvalues[7][4] =11;

    // white pawns
    for (int i = 0; i < 8; i++)
    {
        whitePawns.resize(8);
        whitePawns[i] = new QGraphicsRectItem(-225+60*i, -105, 30, 30 );
        whitePawns[i]->setBrush(greenBrush);
        scene->addItem(whitePawns[i]);
    }
    //black pawns
    for (int i = 0; i < 8; i++)
    {
        blackPawns.resize(8);
        blackPawns[i] = new QGraphicsRectItem(-225+60*i, 195, 30, 30 );
        blackPawns[i]->setBrush(darkGreenBrush);
        scene->addItem(blackPawns[i]);
    }

    // white and black pieces
    for (int i = 0; i < 2; i++)
    {
        whiteRooks.resize(2);
        whiteRooks[i] = new QGraphicsRectItem(-225+420*i,-165,30,30);
        whiteRooks[i]->setBrush(redBrush);
        scene->addItem(whiteRooks[i]);

        blackRooks.resize(2);
        blackRooks[i] = new QGraphicsRectItem(-225+420*i,255,30,30);
        blackRooks[i]->setBrush(darkRedBrush);
        scene->addItem(blackRooks[i]);

        whiteKnights.resize(2);
        whiteKnights[i] = new QGraphicsRectItem(-165+300*i,-165,30,30);
        whiteKnights[i]->setBrush(yellowBrush);
        scene->addItem(whiteKnights[i]);

        blackKnights.resize(2);
        blackKnights[i] = new QGraphicsRectItem(-165+300*i,255,30,30);
        blackKnights[i]->setBrush(darkYellowBrush);
        scene->addItem(blackKnights[i]);

        whiteBishops.resize(2);
        whiteBishops[i] = new QGraphicsRectItem(-105+180*i,-165,30,30);
        whiteBishops[i]->setBrush(blueBrush);
        scene->addItem(whiteBishops[i]);

        blackBishops.resize(2);
        blackBishops[i] = new QGraphicsRectItem(-105+180*i,255,30,30);
        blackBishops[i]->setBrush(darkBlueBrush);
        scene->addItem(blackBishops[i]);
    }


    whiteQueen = new QGraphicsRectItem(-45,-165,30,30);
    whiteQueen->setBrush(magentaBrush);
    scene->addItem(whiteQueen);

    blackQueen = new QGraphicsRectItem(-45,255,30,30);
    blackQueen->setBrush(darkMagentaBrush);
    scene->addItem(blackQueen);

    whiteKing = new QGraphicsRectItem(15,-165,30,30);
    whiteKing->setBrush(grayBrush);
    scene->addItem(whiteKing);

    blackKing = new QGraphicsRectItem(15,255,30,30);
    blackKing->setBrush(darkGrayBrush);
    scene->addItem(blackKing);

}
	treeVisualiserFrame::treeVisualiserFrame(const observationTree& tree, float pointSize)
		:pointSize(pointSize), highlightItem(NULL)
	{
		graphicsScene = new QGraphicsScene();
		graphicsScene->installEventFilter(this);
		graphicsScene->setItemIndexMethod(QGraphicsScene::NoIndex);

		graphicsView = new ZoomGraphicsView(graphicsScene);
		graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
		graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
		graphicsView->installEventFilter(this);

		const observationTree::treeGraphType treeGraph = tree.getTreeGraph();
		observationTree::treeGraphType::vertex_iterator currentVertex, endVertex;
		boost::tie(currentVertex, endVertex) = boost::vertices(treeGraph);

		QPen blackPen(QColor("black"));
		blackPen.setStyle(Qt::NoPen);
		QBrush blueBrush(QColor("blue"));
		QBrush redBrush(QColor("red"));
		for(; currentVertex != endVertex; currentVertex++)
		{
			float x = treeGraph[*currentVertex].x;
			float y = treeGraph[*currentVertex].y;
			treeVisualiserVertex* vertexItem = new treeVisualiserVertex(x - pointSize/2, y - pointSize/2, pointSize, pointSize);
			vertexItem->setVertexID((int)*currentVertex);
			if(treeGraph[*currentVertex].potentiallyDisconnected)
			{
				vertexItem->setPen(blackPen);
				vertexItem->setBrush(blueBrush);
			}
			else
			{
				vertexItem->setPen(blackPen);
				vertexItem->setBrush(redBrush);
			}
			vertexItem->setFlag(QGraphicsItem::ItemIsSelectable, true);
			graphicsScene->addItem(vertexItem);
		}

		blackPen.setStyle(Qt::SolidLine);
		blackPen.setWidthF(pointSize/8);
		observationTree::treeGraphType::edge_iterator currentEdge, endEdge;
		boost::tie(currentEdge, endEdge) = boost::edges(treeGraph);
		for(; currentEdge != endEdge; currentEdge++)
		{
			int sourceVertex = (int)boost::source(*currentEdge, treeGraph);
			int targetVertex = (int)boost::target(*currentEdge, treeGraph);
			float sourceX = treeGraph[sourceVertex].x;
			float sourceY = treeGraph[sourceVertex].y;
			float targetX = treeGraph[targetVertex].x;
			float targetY = treeGraph[targetVertex].y;

			QGraphicsLineItem* lineItem = graphicsScene->addLine(sourceX, sourceY, targetX, targetY, blackPen);
			lineItem->setFlag(QGraphicsItem::ItemIsSelectable, false);
		}
		layout = new QHBoxLayout;
		layout->addWidget(graphicsView, 1);
		layout->setContentsMargins(0,0,0,0);
		setLayout(layout);
		graphicsView->fitInView(graphicsView->sceneRect(), Qt::KeepAspectRatioByExpanding);
	}
Exemple #13
0
void
MFCClipItemView::Draw(Graphics &dc, CRect &clipBox)
{
// !!!??? need to clip properly for short instances with long names
	cerr << "clip item draw " << item->sym->name << endl;
	Pen blackPen(Color(250, 0, 0, 0), 1);
	Pen redPen(Color(250, 238, 100, 100), 1);
	Pen orangePen(Color(200, 250, 150, 10), 1);
	SolidBrush blueBrush(Color(100, 100, 100, 238));
	SolidBrush blackBrush(Color(200, 0, 0, 0));
	SolidBrush orangeBrush(Color(190, 250, 150, 10));

	dc.DrawLine( &orangePen, bounds.left, 0, bounds.left, bounds.bottom);
	bool	isMarker = false;
	if (item != NULL && item->duration.ticks <= 0) {
		isMarker = true;
	}
	if (!isMarker) {
		dc.DrawLine( &orangePen, bounds.right, 0, bounds.right, bounds.bottom);
	}

	PointF	tri[3];

	Font	labelFont(L"Arial", 8.0, FontStyleRegular, UnitPoint, NULL);
	wstring nm;
	const char *cp = item->sym->uniqueName();
	while (*cp) {
		nm.push_back(*cp++);
	}
	PointF	p;
	UINT py = 0;
	do {
		if (!isMarker) {
			// a triangle bit
			tri[0].X = bounds.left; tri[0].Y = py;
			tri[1].X = bounds.left+6; tri[1].Y = py+3;
			tri[2].X = bounds.left; tri[2].Y = py+6;
			dc.FillPolygon(&orangeBrush, tri, 3);
		}

		p.X = bounds.left-1;
		p.Y = py+5;
		RectF	box;
		StringFormat	sff = StringFormatFlagsDirectionVertical;
		dc.MeasureString(nm.c_str(), -1, &labelFont, p, &sff, &box);
		dc.DrawString(nm.c_str(), -1, &labelFont, box,	&sff, &blackBrush);

		if (!isMarker) {
			// a nother triangle bit
			tri[0].X = bounds.right;
			tri[1].X = bounds.right-6;
			tri[2].X = bounds.right;
			dc.FillPolygon(&orangeBrush, tri, 3);

			p.X = bounds.right-10;
			p.Y = py+5;
			dc.MeasureString(nm.c_str(), -1, &labelFont, p, &sff, &box);
			dc.DrawString(nm.c_str(), -1, &labelFont, box,	&sff, &blackBrush);
		}
		py += editor->bounds.bottom;
	} while (py < bounds.bottom);

}
Exemple #14
0
// Build the calibration "step" graph which will appear on the lefthand side of the panels
wxBitmap CalReviewDialog::CreateGraph(bool AO)
{
    wxMemoryDC memDC;
    wxBitmap bmp(CALREVIEW_BITMAP_SIZE, CALREVIEW_BITMAP_SIZE, -1);
    wxPen axisPen("BLACK", 3, wxCROSS_HATCH);
    wxPen redPen("RED", 3, wxSOLID);
    wxPen bluePen("BLUE", 3, wxSOLID);
    wxBrush redBrush("RED", wxSOLID);
    wxBrush blueBrush("BLUE", wxSOLID);
    CalibrationDetails calDetails;
    double scaleFactor;
    int ptRadius;

    if (!pSecondaryMount)
    {
        pMount->GetCalibrationDetails(&calDetails);                              // Normal case, no AO
    }
    else
    {
        if (AO)
        {
            pMount->GetCalibrationDetails(&calDetails);                          // AO tab, use AO details
        }
        else
        {
            pSecondaryMount->GetCalibrationDetails(&calDetails);                 // Mount tab, use mount details
        }
    }

    // Find the max excursion from the origin in order to scale the points to fit the bitmap
    double biggestVal = -100.0;
    for (std::vector<wxRealPoint>::const_iterator it = calDetails.raSteps.begin(); it != calDetails.raSteps.end(); ++it)
    {
        biggestVal = wxMax(biggestVal, fabs(it->x));
        biggestVal = wxMax(biggestVal, fabs(it->y));
    }

    for (std::vector<wxRealPoint>::const_iterator it = calDetails.decSteps.begin(); it != calDetails.decSteps.end(); ++it)
    {
        biggestVal = wxMax(biggestVal, fabs(it->x));
        biggestVal = wxMax(biggestVal, fabs(it->y));
    }

    if (biggestVal > 0.0)
        scaleFactor = ((CALREVIEW_BITMAP_SIZE - 5) / 2) / biggestVal;           // Leave room for circular point
    else
        scaleFactor = 1.0;

    memDC.SelectObject(bmp);
    memDC.SetBackground(*wxLIGHT_GREY_BRUSH);
    memDC.Clear();
    memDC.SetPen(axisPen);
    // Draw the axes
    memDC.SetDeviceOrigin(wxCoord(CALREVIEW_BITMAP_SIZE / 2), wxCoord(CALREVIEW_BITMAP_SIZE / 2));
    memDC.DrawLine(-CALREVIEW_BITMAP_SIZE / 2, 0, CALREVIEW_BITMAP_SIZE / 2, 0);               // x
    memDC.DrawLine(0, -CALREVIEW_BITMAP_SIZE / 2, 0, CALREVIEW_BITMAP_SIZE / 2);               // y

    if (calDetails.raStepCount > 0)
    {
        // Draw the RA data
        memDC.SetPen(redPen);
        memDC.SetBrush(redBrush);
        ptRadius = 2;

        // Scale the points, then plot them individually
        for (int i = 0; i < (int) calDetails.raSteps.size(); i++)
        {
            if (i == calDetails.raStepCount + 2)        // Valid even for "single-step" calibration
            {
                memDC.SetPen(wxPen("Red", 1));         // 1-pixel-thick red outline
                memDC.SetBrush(wxNullBrush);           // Outline only for "return" data points
                ptRadius = 3;
            }
            memDC.DrawCircle(IntPoint(calDetails.raSteps.at(i), scaleFactor), ptRadius);
        }
        // Show the line PHD2 will use for the rate
        memDC.SetPen(redPen);
        if ((int)calDetails.raSteps.size() > calDetails.raStepCount)         // New calib, includes return values
            memDC.DrawLine(IntPoint(calDetails.raSteps.at(0), scaleFactor), IntPoint(calDetails.raSteps.at(calDetails.raStepCount), scaleFactor));
        else
            memDC.DrawLine(IntPoint(calDetails.raSteps.at(0), scaleFactor), IntPoint(calDetails.raSteps.at(calDetails.raStepCount - 1), scaleFactor));
    }

    // Handle the Dec data
    memDC.SetPen(bluePen);
    memDC.SetBrush(blueBrush);
    ptRadius = 2;
    if (calDetails.decStepCount > 0)
    {
    for (int i = 0; i < (int) calDetails.decSteps.size(); i++)
        {
            if (i == calDetails.decStepCount + 2)
            {
                memDC.SetPen(wxPen("Blue", 1));         // 1-pixel-thick red outline
                memDC.SetBrush(wxNullBrush);           // Outline only for "return" data points
                ptRadius = 3;
            }
            memDC.DrawCircle(IntPoint(calDetails.decSteps.at(i), scaleFactor), ptRadius);
        }
        // Show the line PHD2 will use for the rate
        memDC.SetPen(bluePen);
        if ((int)calDetails.decSteps.size() > calDetails.decStepCount)         // New calib, includes return values
            memDC.DrawLine(IntPoint(calDetails.decSteps.at(0), scaleFactor), IntPoint(calDetails.decSteps.at(calDetails.decStepCount), scaleFactor));
        else
        memDC.DrawLine(IntPoint(calDetails.decSteps.at(0), scaleFactor), IntPoint(calDetails.decSteps.at(calDetails.decStepCount - 1), scaleFactor));
    }

    memDC.SelectObject(wxNullBitmap);
    return bmp;
}
Exemple #15
0
void MainWindow::on_pushButton_clicked()
{
    this->scene->clear();
    out="自配置\n";
    this->ui->textEdit->setText(out);

    QBrush redBrush(Qt::red);
    QBrush blueBrush(Qt::blue);
    QBrush yellowBrush(Qt::yellow);

    QPen blackPen(Qt::black);
    blackPen.setWidth(0.5);
    QPen bluePen(Qt::blue);
    bluePen.setWidth(0.5);
    self_window = new self_set;
    qDebug()<<"hello"<<endl;
    self_window->exec();
    QDateTime time = QDateTime::currentDateTime();//获取系统现在的时间
    QString _time = time.toString("yyyy-MM-dd hh:mm:ss ddd"); //设置显示格式
    out=out+_time+"\n";
    this->ui->textEdit->setText(out);

    qDebug()<<this->self_window->_yes;
    setAlgo = new Set_algorithm;
    if(this->self_window->_yes==true){
        this->ui->textEdit->setText(out);
        QString ch = (self_window->choice==1)? "平均SINR最高":"能效比最高";
        out=out+"\n自配置参数预制如下:\n-----------------------\n";
        out=out+"RESP0:"+QString::number(self_window->RESP0)+"\n"+
                "优化标准:"+ch+"\n"+
                "路损模型参数:\n"+"a="+QString::number(self_window->a)+"  b="+QString::number(self_window->b)+"\n"
                +"覆盖率:"+QString::number(self_window->coverRate)+"%\n"+
                "额定功率:"+QString::number(self_window->power)+"\n"
                +"临界信噪比:"+QString::number(self_window->SINR)+"\n"+
                "-----------------------\n自配置开始......\n";

        this->ui->textEdit->setText(out);

        setAlgo->RESP0=self_window->RESP0;
        setAlgo->choice=self_window->choice;
        setAlgo->coverRate=self_window->coverRate;
        setAlgo->power=self_window->power;
        setAlgo->SINR = self_window->SINR;
        setAlgo->a=self_window->a;
        setAlgo->b=self_window->b;

        qDebug()<<out;

        QString resultPower=QString::number(setAlgo->getResultPower())+"\n";
        out=out+resultPower;
        this->ui->textEdit->setText(out);

        for(int i=0;i<setAlgo->apList.size();i++){
            AP *temp = setAlgo->apList.at(i);
            qDebug()<<"x,y:"<<temp->x()<<" "<<temp->y()<<endl;

            if(temp->frequency==1)
                this->scene->addEllipse(temp->x(),temp->y(),(setAlgo->ratio)*EXR,(setAlgo->ratio)*EXR,blackPen,blueBrush);
            else if(temp->frequency==6)
                this->scene->addEllipse(temp->x(),temp->y(),(setAlgo->ratio)*EXR,(setAlgo->ratio)*EXR,blackPen,redBrush);
            else if(temp->frequency==11)
                this->scene->addEllipse(temp->x(),temp->y(),(setAlgo->ratio)*EXR,(setAlgo->ratio)*EXR,blackPen,yellowBrush);
        }
    }
    _addLineGraph();
}
Exemple #16
0
void MainWindow::setupMainGraph(int M,int N)
{
    this->_cleanTheList();

    QBrush redBrush(Qt::red);
    QBrush blueBrush(Qt::blue);
    QBrush yellowBrush(Qt::yellow);

    QPen blackPen(Qt::black);
    blackPen.setWidth(0.5);
    QPen bluePen(Qt::blue);
    bluePen.setWidth(0.5);
    srand((int)time(NULL));
    /*
    for(int i=0;i<5;i++){
        elipse[i] = scene->addEllipse(-200+i*100+rand()%30,-110+rand()%30,-100,100,blackPen,redBrush);
        elipse[i]->setFlag(QGraphicsItem::ItemIsMovable);
    }
    for(int i=6;i<11;i++){
        elipse[i] = scene->addEllipse(-200+(i-5)*100+rand()%30,100+rand()%30,-100,100,blackPen,yelloBrush);
        elipse[i]->setFlag(QGraphicsItem::ItemIsMovable);
    }
    for(int i=12;i<19;i++){
        elipse[i] = scene->addEllipse(-200+(i-12)*100+rand()%30,300+rand()%30,-100,100,blackPen,blueBrush);
        elipse[i]->setFlag(QGraphicsItem::ItemIsMovable);
    }

    */


    srand((int)time(NULL));
    for(int j=-N;j<=N;j++){
        for(int i=-M;i<=M;i++){
            blue = new QGraphicsEllipseItem;
            blue = scene->addEllipse(2*sqrt(3)*R*i+RD,6*R*j+RD,2*R+EXTRA,2*R+EXTRA,blackPen,blueBrush);
            blue->setX(2*sqrt(3)*R*i+RD);
            blue ->setY(6*R*j+RD);
            blueElipse.append(blue);
        }
    }

    for(int j=-N;j<=N;j++){
        for(int i=-M;i<=M;i++){
            blue = new QGraphicsEllipseItem;
            blue = scene->addEllipse(-sqrt(3)*R+2*sqrt(3)*R*i+RD,-3*R+6*R*j+RD,2*R+EXTRA,2*R+EXTRA,blackPen,blueBrush);
            blue->setX(-sqrt(3)*R+2*sqrt(3)*R*i+RD);
            blue->setY(-3*R+6*R*j+RD);
            blueElipse.append(blue);
        }
    }

    for(int j=-N;j<=N;j++){
        for(int i=-M;i<=M;i++){
            red = new QGraphicsEllipseItem;
            red = scene->addEllipse(2*sqrt(3)*R*i+RD,2*R+6*R*j+RD,2*R+EXTRA,2*R+EXTRA,blackPen,redBrush);
            red->setX(2*sqrt(3)*R*i+RD);
            red->setY(2*R+6*R*j+RD);
            redElipse.append(red);
        }
    }

    for(int j=-N;j<=N;j++){
        for(int i=-M;i<=M;i++){
            red = new QGraphicsEllipseItem;
            red = scene->addEllipse(-sqrt(3)*R+2*sqrt(3)*R*i+RD,-R+6*R*j+RD,2*R+EXTRA,2*R+EXTRA,blackPen,redBrush);
            red->setX(-sqrt(3)*R+2*sqrt(3)*R*i+RD);
            red->setY(-R+6*R*j+RD);
            redElipse.append(red);
        }
    }
    for(int j=-N;j<=N;j++){
        for(int i=-M;i<=M;i++){
            yellow = new QGraphicsEllipseItem;
            yellow = scene->addEllipse(-sqrt(3)*R+2*sqrt(3)*R*i+RD,R+6*R*j+RD,2*R+EXTRA,2*R+EXTRA,blackPen,yellowBrush);
            yellow->setX(-sqrt(3)*R+2*sqrt(3)*R*i+RD);
            yellow->setY(R+6*R*j+RD);
            yellowElipse.append(yellow);
        }
    }

    for(int j=-N;j<=N;j++){
        for(int i=-M;i<=M;i++){
            yellow = new QGraphicsEllipseItem;
            yellow = scene->addEllipse(2*sqrt(3)*R*i+RD,-2*R+6*R*j+RD,2*R+EXTRA,2*R+EXTRA,blackPen,yellowBrush);
            yellow ->setX(2*sqrt(3)*R*i+RD);
            yellow ->setY(-2*R+6*R*j+RD);
            yellowElipse.append(yellow);
        }
    }

    qDebug()<<redElipse.size();

    foreach(QGraphicsEllipseItem *red,redElipse){
        red->setFlag(QGraphicsItem::ItemIsMovable);
        qDebug()<<red->x()<<" "<<red->y()<<endl;
    }