/* * BlowupImage - stretch the view window into the window given by hwnd */ void BlowupImage( HWND hmdiwnd, WPI_PRES pres ) { HDC memdc; WPI_PRES mempres; WPI_RECT client; HBITMAP oldbitmap; HBITMAP newbitmap; HWND hwnd; img_node *node; BOOL new_pres; if( hmdiwnd != NULL ) { hwnd = hmdiwnd; } else { node = GetCurrentNode(); if( node == NULL ) { return; } hwnd = node->hwnd; } newbitmap = EnlargeImage( hwnd ); if( newbitmap == NULL ) { return; } new_pres = FALSE; if( pres == (WPI_PRES)NULL ) { pres = _wpi_getpres( hwnd ); new_pres = TRUE; } mempres = _wpi_createcompatiblepres( pres, Instance, &memdc ); oldbitmap = _wpi_selectobject( mempres, newbitmap ); if( ImgedConfigInfo.grid_on ) { showGrid( hwnd, mempres ); } else { GetClientRect( hwnd, &client ); _wpi_bitblt( pres, 0, 0, _wpi_getwidthrect( client ), _wpi_getheightrect( client ), mempres, 0, 0, SRCCOPY ); RedrawPrevClip( hwnd ); // Redraw if there was a clip region specified. } _wpi_selectobject( mempres, oldbitmap ); _wpi_deletebitmap( newbitmap ); _wpi_deletecompatiblepres( mempres, memdc ); if( new_pres ) { _wpi_releasepres( hwnd, pres ); } } /* BlowupImage */
int MovableTableWidget::sizeHintForColumn(int column) const { ensurePolished(); QStyleOptionViewItem option = viewOptions(); int hint = 0; QModelIndex index; for (int row = 0; row <= rowCount(); ++row) { index = indexFromItem(item(row, column)); hint = qMax(hint, itemDelegate(index)->sizeHint(option, index).width()); } return showGrid() ? hint + 1 : hint; }
int QCustomTableWidget::sizeHintForColumn(int column) const { QStyleOptionViewItem option(viewOptions()); int hint = 0; QAbstractItemDelegate *delegate = itemDelegate(); QAbstractItemModel *itemModel = model(); for(int row = 0; row < rowCount(); row++) { hint = qMax(hint, delegate->sizeHint(option, itemModel->index(row,column)).width()); } if (showGrid()) { hint++; } return hint; }
void UiSettings::loadSettings() { QSettings s( "CS224", "snow" ); windowPosition() = s.value( "windowPosition", QPoint(0,0) ).toPoint(); windowSize() = s.value( "windowSize", QSize(1000,800) ).toSize(); fillNumParticles() = s.value( "fillNumParticles", 512*128 ).toInt(); fillResolution() = s.value( "fillResolution", 0.05f ).toFloat(); fillDensity() = s.value( "fillDensity", 150.f ).toFloat(); exportDensity() = s.value("exportDensity", false).toBool(); exportVelocity() = s.value("exportVelocity", false).toBool(); exportFPS() = s.value("exportFPS", 24).toInt(); maxTime() = s.value("maxTime", 3).toFloat(); gridPosition() = vec3( s.value("gridPositionX", 0.f).toFloat(), s.value("gridPositionY", 0.f).toFloat(), s.value("gridPositionZ", 0.f).toFloat() ); gridDimensions() = glm::ivec3( s.value("gridDimensionX", 128).toInt(), s.value("gridDimensionY", 128).toInt(), s.value("gridDimensionZ", 128).toInt() ); gridResolution() = s.value( "gridResolution", 0.05f ).toFloat(); timeStep() = s.value( "timeStep", 1e-5 ).toFloat(); implicit() = s.value( "implicit", true ).toBool(); materialPreset() = s.value( "materialPreset", MAT_DEFAULT).toInt(); showContainers() = s.value( "showContainers", true ).toBool(); showContainersMode() = s.value( "showContainersMode", WIREFRAME ).toInt(); showColliders() = s.value( "showColliders", true ).toBool(); showCollidersMode() = s.value( "showCollidersMode", SOLID ).toInt(); showGrid() = s.value( "showGrid", false ).toBool(); showGridMode() = s.value( "showGridMode", MIN_FACE_CELLS ).toInt(); showGridData() = s.value( "showGridData", false ).toBool(); showGridDataMode() = s.value( "showGridDataMode", NODE_DENSITY ).toInt(); showParticles() = s.value( "showParticles", true ).toBool(); showParticlesMode() = s.value( "showParticlesMode", PARTICLE_MASS ).toInt(); selectionColor() = glm::vec4( 0.302f, 0.773f, 0.839f, 1.f ); }
WSpacePlot::WSpacePlot(QSize size, bool dg, QWidget* parent, QWidget *colorBarParent, WGraphXAxis::Position xAxisPos, WGraphYAxis::Position yAxisPos, int border) : WGraphWidget(parent,xAxisPos,yAxisPos,border), paintColor(red), dataRange(0.0, 1.0), recRects(0), cellLabelRect(QRect()), colorBar(0), startCell(0,0), currCell(0,0), selecting(true), dragEnabled(false), drawGrid(dg), autoScale(true), multiSelect(true) { if (colorBarParent) { colorBar = new WColorBar(colorBarParent); connect(this,SIGNAL(colorChanged(QColor)), colorBar,SLOT(setColor(QColor))); connect(colorBar,SIGNAL(rangeSelected(WRange)), this,SLOT(selectRange(WRange))); connect(colorBar,SIGNAL(yVisRangeChanged(WRange)), this,SLOT(setDataRange(WRange))); colorBar->show(); } setCursor(crossCursor); if (drawGrid) setBackgroundColor(white); setFocusPolicy(TabFocus); xAxis()->setBaseTick(1.0); yAxis()->setBaseTick(1.0); showGrid(false); setSize(size); autoPanTimer = new QTimer(this); labelClearTimer = new QTimer(this); connect(frame(),SIGNAL(aboutToDraw()),this,SLOT(checkDataRange())); connect(autoPanTimer,SIGNAL(timeout()),this,SLOT(autoPan())); connect(labelClearTimer,SIGNAL(timeout()),this,SLOT(clearCellLabel())); connect(this,SIGNAL(frameResized()),SLOT(calcGeometry())); connect(this,SIGNAL(visRangeChanged()),SLOT(calcGeometry())); }
void EditLayer::switchCtrlLayerVisible() { CtrlLayer* layer = dynamic_cast<CtrlLayer*>(this->getChildByTag(TAG_CONTROL_LAYER)); if (layer == nullptr) { layer = CtrlLayer::create(); this->addChild(layer, kZorderCtrlLayer, TAG_CONTROL_LAYER); layer->setVisible(false); layer->setSectionStageId(_sectionId, _stageId); } layer->setBulletCounts(_bulletCounter[BallBase::kTypeBullet1], _bulletCounter[BallBase::kTypeBullet2], _bulletCounter[BallBase::kTypeBullet3]); layer->setPosition(0.0, 0.0); showGrid(!layer->isVisible()); layer->setVisible(!layer->isVisible()); }
void GraphEditor::load(bool initgrid) // by default initgrid = true // when editing (erasing edges, vertices,reorienting) initgrid = false { if(!is_init) //MAC {gwp->canvas->setSceneRect(0,0,contentsRect().width(),contentsRect().height()); is_init=true; } //if(!is_init)return; clear();// delete all items if(gwp->pGG->nv() > staticData::MaxND) {Tprintf("Too big graph nv= %d (>%d)",gwp->pGG->nv(),staticData::MaxND);return;} GeometricGraph & G = *(gwp->pGG); if(initgrid) {Normalise(); InitGrid(current_grid); } DrawGrid(current_grid); if(ShowGrid)showGrid(true); Prop<NodeItem *> nodeitem(G.Set(tvertex()),PROP_CANVAS_ITEM,(NodeItem *)NULL); Prop<EdgeItem *> edgeitem(G.Set(tedge()),PROP_CANVAS_ITEM,(EdgeItem *)NULL); nodeitem.SetName("nodeitem");edgeitem.SetName("edgeitem"); for(tvertex v = 1;v <= G.nv();v++) nodeitem[v] = CreateNodeItem(v,gwp); for(tedge e = 1;e <= G.ne();e++) edgeitem[e] = CreateEdgeItem(e,gwp); if(staticData::ShowExtTbrin()) {tedge e = G.extbrin().GetEdge(); EdgeItem *edge = (G.extbrin() > 0) ? edgeitem[e] : edgeitem[e]->opp; edge->SetColor(color[Green],false); } Prop<bool> eoriented(G.Set(tedge()),PROP_ORIENTED,false); CreateColorItems(gwp,color_node,color_edge); G.vcolor.definit(color_node); G.vlabel.definit(0L); G.elabel.definit(0L); CreateThickItems(gwp,width_edge); G.ewidth.definit(width_edge); }
void UiSettings::saveSettings() { QSettings s( "CS224", "snow" ); s.setValue( "windowPosition", windowPosition() ); s.setValue( "windowSize", windowSize() ); s.setValue( "fillNumParticles", fillNumParticles() ); s.setValue( "fillResolution", fillResolution() ); s.setValue( "fillDensity", fillDensity() ); s.setValue("exportDensity", exportDensity()); s.setValue("exportVelocity",exportVelocity()); s.setValue( "exportFPS", exportFPS()); s.setValue( "maxTime", maxTime()); s.setValue( "gridPositionX", gridPosition().x ); s.setValue( "gridPositionY", gridPosition().y ); s.setValue( "gridPositionZ", gridPosition().z ); s.setValue( "gridDimensionX", gridDimensions().x ); s.setValue( "gridDimensionY", gridDimensions().y ); s.setValue( "gridDimensionZ", gridDimensions().z ); s.setValue( "gridResolution", gridResolution() ); s.setValue( "timeStep", timeStep() ); s.setValue( "implicit", implicit() ); s.setValue("materialPreset", materialPreset()); s.setValue( "showContainers", showContainers() ); s.setValue( "showContainersMode", showContainersMode() ); s.setValue( "showColliders", showColliders() ); s.setValue( "showCollidersMode", showCollidersMode() ); s.setValue( "showGrid", showGrid() ); s.setValue( "showGridMode", showGridMode() ); s.setValue( "showGridData", showGridData() ); s.setValue( "showGridDataMode", showGridDataMode() ); s.setValue( "showParticles", showParticles() ); s.setValue( "showParticlesMode", showParticlesMode() ); }
ThreeDVisualizationTool::ThreeDVisualizationTool(QWidget* parent, CelestiaGlWidget* celestiaView, CelestiaInterface* celestia, CelestiaCore* celestiaCore) : QWidget(parent), m_celestiaView(celestiaView), m_celestia(celestia), m_celestiaCore(celestiaCore), m_sun(NULL), m_ssb(NULL) { // Create and hook up the tool bar VisualizationToolBar* toolBar = new VisualizationToolBar(tr("3D View Controls"), this); connect(toolBar, SIGNAL(bodyChanged(const StaBody*)), this, SLOT(gotoBody(const StaBody*))); connect(toolBar, SIGNAL(gridToggled(bool)), this, SLOT(showGrid(bool))); connect(toolBar, SIGNAL(tickIntervalChanged(double)), this, SLOT(setTickInterval(double))); //connect(toolBar, SIGNAL(projectionChanged(bool)), m_view, SLOT(set2HalfDView(bool))); connect(toolBar, SIGNAL(saveImageRequested()), this, SLOT(saveImage())); QVBoxLayout* layout = new QVBoxLayout(this); layout->setSpacing(1); layout->setContentsMargins(3, 3, 3, 3); layout->addWidget(m_celestiaView); layout->addWidget(toolBar); setLayout(layout); Selection sun = celestiaCore->getSimulation()->getUniverse()->find("Sol"); m_sun = sun.star(); Selection ssb = celestiaCore->getSimulation()->getUniverse()->find("SSB"); m_ssb = ssb.star(); // Sync 3D view state with toolbar settings //showGrid(true); showGrid(false); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); }
/*! MyWindow constructor * \param w - window width * \param h - window hight */ MyWindow::MyWindow(int w, int h) : num_of_colors(18) { myBar = new QTabWidget(this); setCentralWidget(myBar); m_width = w; m_height = h; tab_number = 0; number_of_tabs = 0; testlayer = new Qt_layer( myBar ); colors_flag = true; statusBar(); m_scailing_factor = 2; // Traits Group QActionGroup *traitsGroup = new QActionGroup( this ); // Connected later traitsGroup->setExclusive( TRUE ); /*setSegmentTraits = new QAction("Segment Traits", QPixmap( (const char**)line_xpm ), "&Segment Traits", 0 ,traitsGroup, "Segment Traits" ); setSegmentTraits->setToggleAction( TRUE ); setPolylineTraits = new QAction("Polyline Traits", QPixmap( (const char**)polyline_xpm ), "&Polyline Traits", 0 , traitsGroup, "Polyline Traits" ); setPolylineTraits->setToggleAction( TRUE ); #ifdef CGAL_USE_CORE setConicTraits = new QAction("Conic Traits", QPixmap( (const char**)conic_xpm ), "&Conic Traits", 0 , traitsGroup, "Conic Traits" ); setConicTraits->setToggleAction( TRUE ); #endif */ // Snap Mode Group setSnapMode = new QAction("Snap Mode", QPixmap( (const char**)snapvertex_xpm ), "&Snap Mode", 0 , this, "Snap Mode" ); setSnapMode->setToggleAction( TRUE ); setGridSnapMode = new QAction("Grid Snap Mode", QPixmap( (const char**)snapgrid_xpm ), "&Grid Snap Mode", 0 , this, "Grid Snap Mode" ); setGridSnapMode->setToggleAction( TRUE ); // insert - delete - point_location Mode Group QActionGroup *modeGroup = new QActionGroup( this ); // Connected later modeGroup->setExclusive( TRUE ); insertMode = new QAction("Insert", QPixmap( (const char**)insert_xpm ), "&Insert", 0 , modeGroup, "Insert" ); insertMode->setToggleAction( TRUE ); deleteMode = new QAction("Delete", QPixmap( (const char**)delete_xpm ), "&Delete", 0 , modeGroup, "Delete" ); deleteMode->setToggleAction( TRUE ); pointLocationMode = new QAction("PointLocation", QPixmap( (const char**)pointlocation_xpm ), "&Point Location", 0 , modeGroup, "Point Location" ); pointLocationMode->setToggleAction( TRUE ); dragMode = new QAction("Drag", QPixmap( (const char**)hand_xpm ), "&Drag", 0 , modeGroup, "Drag" ); dragMode->setToggleAction( TRUE ); // zoom in zoominBt = new QAction("Zoom in", QPixmap( (const char**)zoomin_xpm ), "&Zoom in", 0 , this, "Zoom in" ); // zoom out zoomoutBt = new QAction("Zoom out", QPixmap( (const char**)zoomout_xpm ), "&Zoom out", 0 , this, "Zoom out" ); // color dialog color_dialog_bt = new QAction("Choose color", QPixmap( (const char**)demo_colors_xpm ), "&choose color", 0 , this, "choose color" ); // Cartograms carto_new = new QAction("New instance", QPixmap( (const char**)carto_new_xpm ), "&New instance", 0 , this, "New instance" ); carto_weights = new QAction("Set weights", QPixmap( (const char**)carto_weights_xpm ), "&Set weights", 0 , this, "Set weights" ); carto_start = new QAction("Start Cartogram", QPixmap( (const char**)carto_start_xpm ), "&Start Cartogram", 0 , this, "Start Cartogram" ); carto_it = new QAction("Next step", QPixmap( (const char**)carto_nextIt_xpm ), "&Next step", 0 , this, "Next step" ); /* #ifdef CGAL_USE_CORE // Conic Type Group QActionGroup *conicTypeGroup = new QActionGroup( this ); // Connected later conicTypeGroup->setExclusive( TRUE ); setCircle = new QAction("Circle", QPixmap( (const char**)demo_conic_circle_xpm ), "&Circle", 0 ,conicTypeGroup, "Circle" ); setCircle->setToggleAction( TRUE ); setSegment = new QAction("Segment", QPixmap( (const char**)demo_conic_segment_xpm ), "&Segment", 0 ,conicTypeGroup, "Segment" ); setSegment->setToggleAction( TRUE ); setEllipse = new QAction("Ellipse", QPixmap( (const char**)demo_conic_ellipse_xpm ), "&Ellipse", 0 ,conicTypeGroup, "Ellipse" ); setEllipse->setToggleAction( TRUE ); setParabola = new QAction("3 Points Arc", QPixmap( (const char**)demo_conic_3points_xpm ), "&3 Points Arc", 0 ,conicTypeGroup, "3 Points Arc" ); setParabola->setToggleAction( TRUE ); setHyperbola = new QAction("5 Points Arc", QPixmap( (const char**)demo_conic_5points_xpm ), "&5 Points Arc", 0 ,conicTypeGroup, "5 Points Arc" ); setHyperbola->setToggleAction( TRUE ); #endif */ //create a timer for checking if somthing changed QTimer *timer = new QTimer( this ); connect( timer, SIGNAL(timeout()), this, SLOT(timer_done()) ); timer->start( 200, FALSE ); // file menu QPopupMenu * file = new QPopupMenu( this ); menuBar()->insertItem( "&File", file ); /* file->insertItem("&Open Segment File...", this, SLOT(fileOpenSegment())); file->insertItem("&Open Polyline File...", this, SLOT(fileOpenPolyline()));\ file->insertItem("&Open Segment Arr File...", this, SLOT(fileOpenSegmentPm())); file->insertItem("&Open Polyline Arr File...", this, SLOT(fileOpenPolylinePm())); file->insertItem("&Open Conic Pm File", this, SLOT(fileOpenConicPm())); */ file->insertItem("&Open Input File...", this, SLOT(fileOpenSegment())); file->insertItem("&Open Output File...", this, SLOT(fileOpenConic())); file->insertItem("&Save...", this, SLOT(fileSave())); file->insertItem("&Save As...", this, SLOT(fileSaveAs())); //file->insertItem("&Save to ps...", this, SLOT(fileSave_ps())); file->insertSeparator(); file->insertItem("&Print...", this , SLOT(print())); file->insertSeparator(); file->insertItem( "&Close", this, SLOT(close()), CTRL+Key_X ); file->insertItem( "&Quit", qApp, SLOT( closeAllWindows() ), CTRL+Key_Q ); menuBar()->insertSeparator(); // tab menu QPopupMenu * tab = new QPopupMenu( this ); menuBar()->insertItem( "&Tab", tab ); /* tab->insertItem("Add &Segment Tab", this, SLOT(add_segment_tab())); tab->insertItem("Add &Polyline Tab", this, SLOT(add_polyline_tab())); #ifdef CGAL_USE_CORE tab->insertItem("Add &Conic Tab", this, SLOT(add_conic_tab())); tab->insertSeparator(); #endif */ tab->insertItem("Remove &Tab", this, SLOT(remove_tab())); menuBar()->insertSeparator(); // mode menu QPopupMenu * mode = new QPopupMenu( this ); menuBar()->insertItem( "&Mode", mode ); insertMode->addTo( mode ); deleteMode->addTo( mode ); pointLocationMode->addTo( mode ); dragMode->addTo( mode ); menuBar()->insertSeparator(); // snap mode menu QPopupMenu * snap_mode = new QPopupMenu( this ); menuBar()->insertItem( "&Snap mode", snap_mode ); setSnapMode->addTo(snap_mode); setGridSnapMode->addTo(snap_mode); menuBar()->insertSeparator(); // traits menu /*QPopupMenu * traits = new QPopupMenu( this ); menuBar()->insertItem( "&Traits Type", traits ); setSegmentTraits->addTo(traits); setPolylineTraits->addTo(traits); #ifdef CGAL_USE_CORE setConicTraits->addTo(traits); #endif */ // options menu QPopupMenu * options = new QPopupMenu( this ); menuBar()->insertItem( "&Options", options ); options->insertSeparator(); //options->insertItem("Overlay...", this, SLOT(overlay_pm())); options->insertSeparator(); options->insertItem("Properties...", this, SLOT(properties())); options->insertSeparator(); options->insertItem("Show Grid", this, SLOT(showGrid())); options->insertItem("Hide Grid", this, SLOT(hideGrid())); options->insertSeparator(); //options->insertItem("Conic Type", this, SLOT(conicType())); //options->insertSeparator(); options->insertItem("Unbounded Face Color...", this, SLOT(backGroundColor())); options->insertSeparator(); options->insertItem("Edge Color...", this, SLOT(changeEdgeColor())); options->insertSeparator(); options->insertItem("Vertex Color...", this, SLOT(changeVertexColor())); options->insertSeparator(); /*options->insertItem("Point-Locaiton Strategy....", this , SLOT(pointLocationStrategy())); */ QToolBar *modeTools = new QToolBar( this, "mode operations" ); modeTools->setLabel( "Mode Operations" ); insertMode->addTo( modeTools ); deleteMode->addTo( modeTools ); pointLocationMode->addTo( modeTools ); dragMode->addTo( modeTools ); modeTools->addSeparator(); QToolBar *snapModeTools = new QToolBar( this, "snapMode operations" ); snapModeTools->setLabel( "Snap Mode Operations" ); snapModeTools->addSeparator(); setSnapMode->addTo( snapModeTools ); setGridSnapMode->addTo( snapModeTools ); snapModeTools->addSeparator(); /*QToolBar *traitsTool = new QToolBar( this, "traits type" ); traitsTool->setLabel( "Traits Type" ); traitsTool->addSeparator(); setSegmentTraits->addTo( traitsTool ); setPolylineTraits->addTo( traitsTool ); #ifdef CGAL_USE_CORE setConicTraits->addTo( traitsTool ); #endif traitsTool->addSeparator(); */ QToolBar *zoomTool = new QToolBar( this, "zoom" ); zoomTool->setLabel( "Zoom" ); zoomTool->addSeparator(); zoomoutBt->addTo( zoomTool ); zoominBt->addTo( zoomTool ); zoomTool->addSeparator(); QToolBar *colorTool = new QToolBar( this, "color" ); colorTool->addSeparator(); colorTool->setLabel("Choose color"); color_dialog_bt->addTo(colorTool); colorTool->addSeparator(); QToolBar *cartoTool = new QToolBar( this, "cartograms" ); cartoTool->addSeparator(); cartoTool->setLabel("Cartograms"); carto_new->addTo(cartoTool); carto_weights->addTo(cartoTool); carto_start->addTo(cartoTool); carto_it->addTo(cartoTool); cartoTool->addSeparator(); /* #ifdef CGAL_USE_CORE conicTypeTool = new QToolBar( this, "conic type" ); conicTypeTool->setLabel( "Conic Type" ); conicTypeTool->addSeparator(); setSegment->addTo( conicTypeTool ); setCircle->addTo( conicTypeTool ); setEllipse->addTo( conicTypeTool ); setParabola->addTo( conicTypeTool ); setHyperbola->addTo( conicTypeTool ); #endif */ connect( zoomoutBt, SIGNAL( activated () ) , this, SLOT( zoomout() ) ); connect( zoominBt, SIGNAL( activated () ) , this, SLOT( zoomin() ) ); connect (color_dialog_bt , SIGNAL( activated()) , this , SLOT(openColorDialog() ) ); // connect mode group connect( modeGroup, SIGNAL( selected(QAction*) ), this, SLOT( updateMode(QAction*) ) ); // connect Traits Group /* connect( traitsGroup, SIGNAL( selected(QAction*) ), this, SLOT( updateTraitsType(QAction*) ) ); #ifdef CGAL_USE_CORE // connect Conic Type Group connect( conicTypeGroup, SIGNAL( selected(QAction*) ), this, SLOT( updateConicType(QAction*) ) ); #endif */ // connect Snap Mode connect( setSnapMode, SIGNAL( toggled( bool ) ) , this, SLOT( updateSnapMode( bool ) ) ); connect( setGridSnapMode, SIGNAL( toggled( bool ) ) , this, SLOT( updateGridSnapMode( bool ) ) ); // connect the change of current tab connect( myBar, SIGNAL( currentChanged(QWidget * ) ), this, SLOT( update() ) ); // connect cartogram actions connect( carto_start, SIGNAL( activated () ) , this, SLOT( cartogram_start() ) ); connect( carto_weights, SIGNAL( activated () ) , this, SLOT( cartogram_weights() ) ); connect( carto_it, SIGNAL( activated () ) , this, SLOT( print_all_weights())); connect( carto_new, SIGNAL( activated () ) , this, SLOT( cartogram_balance() ) ); colors = new QColor[num_of_colors]; colors[0] = Qt::blue; colors[1] = Qt::gray; colors[2] = Qt::green; colors[3] = Qt::cyan; colors[4] = Qt::magenta; colors[5] = Qt::darkRed; colors[6] = Qt::darkGreen; colors[7] = Qt::darkBlue; colors[8] = Qt::darkMagenta; colors[9] = Qt::darkCyan; colors[10] = Qt::yellow; colors[11] = Qt::white; colors[12] = Qt::darkGray; colors[13] = Qt::gray; colors[14] = Qt::red; colors[15] = Qt::cyan; colors[16] = Qt::darkYellow; colors[17] = Qt::lightGray; //state flag old_state = 0; add_conic_tab(); resize(m_width,m_height); }
int main() { /* * Open the input file. We know it's named zombie.in and * it's in the current directory. Use a stdio file handle * fin for the input file. */ FILE* fin = fopen( "zombies.in", "r" ); /* * The number of levels to process. */ unsigned numLevels; /* * Indicates the current game level. */ unsigned level; /* * Stores the height and width of the level. */ unsigned width; unsigned height; /* * Stores the number of zombies that have been vanquished. */ unsigned numZombies; /* * We'll use a 2-dimensional array of boolean values to store which * locations on the playing field have zombies. The limit on width * and height is 25, but we'll make ours a little bigger just to be * on the safe side. (This will also help using a coordinate system * starting at 1 instead of 0.) */ boolean zombiePresence[30][30]; /* * All x,y coordinates are stored here. This is used to initialize * the zombiePresence and then move Crystel around. */ unsigned x, y; /* * For-loop indices. They are used to read the zombiePresence matrix, * the zombies, and the movements. */ unsigned i, j; /* * Stores the number of steps Crystel will take. */ unsigned numSteps; /* * The direction of a step. */ char direction; /* * Read in the first line, the number of game levels. */ fscanf( fin, "%u\n", &numLevels ); debug_print( "### numLevels=%u\n", numLevels ); /* * Use a loop to read each level, and process as we go. */ for( level = 1; level <= numLevels; ++level ) { /* * Read in the width and height of the playing area for this level */ width = 0; height = 0; fscanf( fin, "%u %u\n", &width, &height ); debug_print( "### width=%u, height=%u\n", width, height ); /* * Start by setting all of our positions to 'false' (ie. no zombie * presence at each location). */ for( i = 0; i <= width; ++i ) { for( j = 0; j <= height; ++j ) { zombiePresence[i][j] = FALSE; } } showGrid( width, height, zombiePresence, 0, 0 ); /* * Read in the number of zombies for this level. */ numZombies = 0; fscanf( fin, "%u\n", &numZombies ); debug_print( "### numZombies=%u\n", numZombies ); /* * Read in the zombie locations, and add them to the grid as we go. */ for( i = 0; i < numZombies; ++i ) { /* * Read a zombie x and y position. */ x = 0; y = 0; fscanf( fin, "%u %u\n", &x, &y ); debug_print( "### zombie #%u: x=%u, y=%u\n", i, x, y ); // added by Nick to verify data if(x > width || x < 1 || y > height || y < 1 || zombiePresence[x][y] == TRUE) fprintf(stderr, "BAD DATA!\n"); /* * Set the zombie presence at that location to 'true'. */ zombiePresence[x][y] = TRUE; showGrid( width, height, zombiePresence, 0, 0 ); } /* * Read in the number of steps Crystel will take on this level. */ fscanf( fin, "%u\n", &numSteps ); debug_print( "### numSteps=%u\n", numSteps ); /* * Crystel starts in the southwest corner, with x and y positions both 1. * She also starts with zero zombies vanquished for each level. */ x = 1; y = 1; numZombies = 0; showGrid( width, height, zombiePresence, x, y ); /* * Is there a zombie at Crystel's starting position? Shoot it! */ if( zombiePresence[x][y] ) { /* KA-BLAM!! Vanquish the zombie */ zombiePresence[x][y] = FALSE; /* record the kill! */ ++numZombies; } /* * Use a loop to read and process each of Crystel's steps on this level. */ for( i = 0; i < numSteps; ++i) { /* * Read in the direction of the step. */ char direction = 'X'; fscanf( fin, "%c\n", &direction ); debug_print( "### direction=%c\n", direction ); /* * Change Crystel's x or y position based on which direction she steps. */ if( 'N' == direction ) ++y; else if( 'S' == direction ) --y; else if( 'E' == direction ) ++x; else if( 'W' == direction ) --x; else fprintf(stderr, "BAD DATA!\n"); // added by Nick to verify data if(x > width || x < 1 || y > height || y < 1) fprintf(stderr, "BAD DATA!\n"); showGrid( width, height, zombiePresence, x, y ); /* * Is there a zombie at Crystel's new position? Shoot it! */ if( zombiePresence[x][y] ) { /* KA-BLAM!! Vanquish the zombie */ zombiePresence[x][y] = FALSE; /* record the kill! */ ++numZombies; } } /* * Crystel is done with the level! Output the number of kills. */ printf( "Level %u: Crystel vanquished %u zombies.\n", level, numZombies ); } fclose( fin ); return 0; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); checkDialog c; c.show(); // shortcuts ui->actionOpen->setShortcut(Qt::Key_O | Qt::CTRL); ui->actionChange_directory->setShortcut(Qt::Key_D | Qt::CTRL); ui->actionClose->setShortcut(Qt::Key_Q | Qt::CTRL); ui->actionRun_F5->setShortcut(Qt::Key_F5); ui->actionClear_case_F6->setShortcut(Qt::Key_F6); ui->actionWrite_input_file_F4->setShortcut(Qt::Key_F4); ui->actionCheck->setShortcut(Qt::Key_F7); QSignalMapper *signalMapper = new QSignalMapper(this); for( int index=0; index < ui->output->count() ; ++index ){ QShortcut *shortcut =new QShortcut( QKeySequence(QString("Ctrl+%1").arg( index +1 ) ), this ); connect( shortcut, SIGNAL(activated() ), signalMapper, SLOT( map() ) ); signalMapper->setMapping( shortcut, index ); } connect( signalMapper, SIGNAL(mapped( int )),ui->output, SLOT(setCurrentIndex( int )) ); // Wave theory ui->widget_SF->setVisible(false); ui->LorP_ComboBox->setVisible(false); ui->widget_waveFile->setVisible(false); QRect SFwidget_geo = ui->widget_SF->geometry(); ui->widget_JONSWAP->setGeometry(SFwidget_geo); ui->widget_JONSWAP->setVisible(false); ui->widget_waveFile->setGeometry(SFwidget_geo); ui->widget_customSpectrum->setVisible(false); ui->widget_customSpectrum->setGeometry(SFwidget_geo); // About ui->aboutText_OCW3dGUI->setVisible(false); ui->aboutText_OCW3D_publications->setVisible(false); ui->aboutText_OCW3DVersion->setVisible(false); // Post processing ui->readProgressBar->setVisible(false); ui->tableWidget->setColumnCount(6); ui->tableWidget->setVisible(false); ui->SelectOutput->setEnabled(false); ui->convert->setEnabled(false); ui->morison_widget->setVisible(false); ui->eta_widget->setVisible(false); QRect Morison_geo = ui->morison_widget->geometry(); ui->eta_widget->setGeometry(Morison_geo); ui->convertStatus->setVisible(false); // Custom grid ui->geometry_table->setRowCount(2); ui->geometry_table->setVerticalHeaderLabels(QString("x [m];d [m]").split(";")); ui->customGridWidget->setVisible(false); // set labels ui->alpha_label->setText(QString((QChar) 0x03B1)); ui->beta_label->setText(QString((QChar) 0x03B2)); ui->gamma_label->setText(QString((QChar) 0x03B3)); connect(ui->waveType,SIGNAL(currentIndexChanged(int)),this,SLOT(on_waveTheoryChanged(int))); connect(ui->storeAscii_onOff,SIGNAL(clicked(bool)),this,SLOT(storeASCII(bool))); connect(ui->LorP_ComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(on_waveTheoryChanged())); connect(ui->nOutFiles,SIGNAL(valueChanged(int)),this,SLOT(on_outputWidgetChanged(int))); connect(ui->OpenDirBrowser,SIGNAL(clicked()),this,SLOT(openWorkDirDialog())); connect(ui->selectPPfile,SIGNAL(clicked()),this,SLOT(selectPPfile())); connect(ui->run,SIGNAL(clicked()),this,SLOT(run())); connect(ui->selectGnuplotFile,SIGNAL(clicked()),this,SLOT(openFileDialog())); connect(ui->plot,SIGNAL(clicked()),this,SLOT(gnuplot())); connect(ui->read_bottom,SIGNAL(clicked()),this,SLOT(readKinematicFile())); connect(ui->about_combobox,SIGNAL(currentIndexChanged(int)),this,SLOT(about_changed(int))); connect(ui->SelectOutput,SIGNAL(currentIndexChanged(int)),this,SLOT(convertTo_setup(int))); connect(ui->convert,SIGNAL(clicked()),this,SLOT(convertTo())); connect(ui->showGrid,SIGNAL(clicked()),this,SLOT(showGrid())); connect(ui->geometryType,SIGNAL(currentIndexChanged(int)),this,SLOT(geometryType_changed(int))); connect(ui->nGridPoints,SIGNAL(valueChanged(int)),this,SLOT(nGridPoints_changed())); connect(ui->smooth,SIGNAL(clicked()),this,SLOT(smooth())); connect(ui->generateGrid,SIGNAL(clicked()),this,SLOT(generateGrid())); connect(ui->selectWaveFile,SIGNAL(clicked()),this,SLOT(selectWaveFile())); connect(ui->selectGridFile,SIGNAL(clicked()),this,SLOT(selectGridFile())); connect(ui->selectWaveFile_eta,SIGNAL(clicked()),this,SLOT(selectWaveFile_eta())); connect(ui->DropDownListOutputType,SIGNAL(currentIndexChanged(int)),this,SLOT(WaveTypeSelected())); connect(ui->pushButton_advancedMorison,SIGNAL(clicked()),this,SLOT(advancedMorison())); // default connect(ui->checkBox_constantWidget,SIGNAL(stateChanged(int)),this,SLOT(constantWidget())); connect(ui->checkBox_breakingWidget,SIGNAL(stateChanged(int)),this,SLOT(breakingWidget())); connect(ui->checkBox_FD,SIGNAL(stateChanged(int)),this,SLOT(FDWidget())); connect(ui->checkBox_precon,SIGNAL(stateChanged(int)),this,SLOT(preconWidget())); // ations connect(ui->actionClose,SIGNAL(triggered()),this,SLOT(close())); connect(ui->actionOpen,SIGNAL(triggered()),this,SLOT(openFile())); connect(ui->actionRun_F5,SIGNAL(triggered()),this,SLOT(run())); connect(ui->actionClear_case_F6,SIGNAL(triggered()),this,SLOT(clearCase())); connect(ui->actionWrite_input_file_F4,SIGNAL(triggered()),this,SLOT(writeInputFile())); connect(ui->actionChange_directory,SIGNAL(triggered()),this,SLOT(openWorkDirDialog())); connect(ui->actionCheck,SIGNAL(triggered()),this,SLOT(checkCase())); ui->workingDir->setText(dir.currentPath()); // Special versions #if externalOutputClass ui->SelectOutput->addItem("External output"); #endif }
void DiagramScene::setValues(QMap<QString, QVector<QPointF> > values) { if(!values.keys().size()) { mouseline=0; clear(); return; } if(!values[values.keys().at(0)].size()) { mouseline=0; clear(); return; } bool dirty = true; int searchiteration=0; while(dirty && searchiteration<1000) { searchiteration++; mouseline=0; clear(); for(int index=0; index < value.size(); index++) delete value[value.keys().at(index)]; value.clear(); minvaluex=0.0; maxvaluex=0.0; minvaluey=0.0; maxvaluey=0.0; if(!yscale) yscale=1; data=values; if(!values.size()) return; for(int index=0; index < values.size(); index++) { QPen pen(QColor(((index+1)*948)%200+50,((index+1)*123)%200+50,((index+1)*11)%200+50)); QPainterPath tmppath; QVector<QPointF> result = values[values.keys().at(index)]; value[data.keys().at(index)] = new QMap<qreal,qreal>(); for(int pointindex=0; pointindex < result.size(); pointindex++) { qreal x = (qreal)(result[pointindex].x()); qreal y = (qreal)(result[pointindex].y()); (*value[data.keys().at(index)])[x]=y; if(!pointindex && !index) { minvaluex=x; maxvaluex=x; minvaluey=(double)y/(double)yscale; maxvaluey=(double)y/(double)yscale; } if(!pointindex) tmppath.moveTo(x*prec,(-y/yscale)*prec); else tmppath.lineTo(x*prec,(-y/yscale)*prec); if(x > maxvaluex) maxvaluex=(double)x; if(x < minvaluex) minvaluex=(double)x; if((double)y/yscale > maxvaluey) maxvaluey=(double)y/yscale; if((double)y/yscale < minvaluey) minvaluey=(double)y/yscale; } addPath(tmppath,pen); } dirty = false; qreal maxyvalue = maxvaluey-minvaluey; if(maxvaluey==minvaluey) maxyvalue = qAbs(maxvaluey); qreal LOWY = 20.0; qreal UPPERY = 80.0; if(maxyvalue < LOWY || maxyvalue > UPPERY) { yscale *=maxyvalue/((double)(UPPERY-LOWY)/2.0 + LOWY); dirty = true; } } showGrid(); qreal w , h; h = maxvaluey-minvaluey; w = maxvaluex-minvaluex; if(w < h * 3) w = h * 3; setSceneRect(minvaluex*prec,-maxvaluey*prec,w*prec, h*prec); QList<QGraphicsView*> viewers = views(); for(int index=0; index < viewers.size(); index++) { viewers.at(index)->fitInView(sceneRect(),Qt::KeepAspectRatioByExpanding); viewers.at(index)->centerOn(maxvaluex*prec,qRound(sceneRect().topRight().y())); } }