void UIOutLink::MouseClick( UIMouse* currentMouse ) { UINodeLink::MouseClick(currentMouse); //we can have multiple LinkStrips so... //create a new one CanvasCoordinates startCoords(getParentCanvas(), getAbsoluteCoordinates() + Vector2f(0.0, getSize().y * .25f)); std::shared_ptr<UILinkStrip> newStrip( new UILinkStrip( getParentCanvas(), this, "lineSTRIP", -1.0f, m_parentDataType->type, m_dataTypeSize, startCoords, startCoords) ); newStrip->Initialize(); newStrip->updateStartTarget( this ); m_draggingStrip = newStrip; }
void UIInLink::MouseClick( UIMouse* currentMouse ) { //if there exists a strip already, start dragging it if(m_linkStrip != nullptr) { //but we want to know about it too //m_draggingStrip = m_linkStrip; // UIOutLink* partner = dynamic_cast<UIOutLink*>(m_linkStrip->getStartTarget()); // if(partner != nullptr) // { // // //make the partner link start dragging the strip // partner->setDraggingStrip( m_linkStrip ); // currentMouse->selectedWidget = partner; // m_linkStrip = nullptr; // } } else { //otherwise create a new one CanvasCoordinates startCoords(getParentCanvas(), getAbsoluteCoordinates() + Vector2f(0.0, getSize().y * .25f)); m_draggingStrip = std::shared_ptr<UILinkStrip>( new UILinkStrip( getParentCanvas(), this, "lineSTRIP", -1.0f, m_parentDataType->type, m_dataTypeSize, startCoords, startCoords) ); m_draggingStrip->Initialize(); m_draggingStrip->updateEndTarget(this); } }
void SAWindow::ShiftCell(int cellInd) { double startFunc = GetFuncValue(); double optimalFunc = startFunc * 1.1; //optimal coordinates must be changed double siteWidth = m_grid.SiteWidth(); double startX = cells[cellInd].XCoord; double startY = cells[cellInd].GetY(); Coordinates startCoords(startX, startY); Coordinates optimalCoords(startX, startY); Coordinates currCoords(startX, startY); int rowInd; for (rowInd = firstRow; rowInd < firstRow + nRows - 1; rowInd++) if (fabs(m_grid.RowY(rowInd) - cells[cellInd].GetY()) < sw_eps) break; rowInd -= firstRow; //index of this row in the window //----------shifting to the left----------------------------------------------------------- if (cellInd == 0) //the first cell { currCoords.xCoord -= siteWidth; while (currCoords.xCoord >= windowBounds[rowInd * 2]) { cells[0].XCoord = currCoords.xCoord; double newFuncValue = GetFuncValue(); if (optimalFunc > newFuncValue) { optimalFunc = newFuncValue; optimalCoords.xCoord = currCoords.xCoord; } currCoords.xCoord -= siteWidth; } currCoords.xCoord += siteWidth; } else //this cell is not the first { double leftCellY = cells[cellInd - 1].GetY(); double leftCellX = cells[cellInd - 1].XCoord + cells[cellInd - 1].width; currCoords.xCoord -= siteWidth; if (leftCellY == startCoords.yCoord) { while (currCoords.xCoord >= leftCellX) { cells[cellInd].XCoord = currCoords.xCoord; double newFuncValue = GetFuncValue(); if (optimalFunc > newFuncValue) { optimalFunc = newFuncValue; optimalCoords.xCoord = currCoords.xCoord; } currCoords.xCoord -= siteWidth; } currCoords.xCoord += siteWidth; } else { while (currCoords.xCoord >= windowBounds[rowInd * 2]) { cells[cellInd].XCoord = currCoords.xCoord; double newFuncValue = GetFuncValue(); if (optimalFunc > newFuncValue) { optimalFunc = newFuncValue; optimalCoords.xCoord = currCoords.xCoord; } currCoords.xCoord -= siteWidth; } currCoords.xCoord += siteWidth; currCoords.xCoord = windowBounds[rowInd * 2 + 3] - cells[cellInd].width; currCoords.yCoord = leftCellY; //m_grid.RowY(rowInd + firstRow); cells[cellInd].YCoord = currCoords.yCoord; while (currCoords.xCoord >= leftCellX) { cells[cellInd].XCoord = currCoords.xCoord; double newFuncValue = GetFuncValue(); if (optimalFunc > newFuncValue) { optimalFunc = newFuncValue; optimalCoords.xCoord = currCoords.xCoord; optimalCoords.yCoord = currCoords.yCoord; } currCoords.xCoord -= siteWidth; } currCoords.xCoord += siteWidth; } } cells[cellInd].XCoord = startCoords.xCoord; cells[cellInd].YCoord = startCoords.yCoord; currCoords.xCoord = cells[cellInd].XCoord + siteWidth; currCoords.yCoord = cells[cellInd].GetY(); //---------------------shifting to the right--------------------------------------------- if (cellInd == nCells - 1) //the last cell { while (currCoords.xCoord <= (windowBounds[rowInd * 2 + 1] - cells[cellInd].width)) ///? { cells[cellInd].XCoord = currCoords.xCoord; double newFuncValue = GetFuncValue(); if (optimalFunc > newFuncValue) { optimalFunc = newFuncValue; optimalCoords.xCoord = currCoords.xCoord; optimalCoords.yCoord = currCoords.yCoord; } currCoords.xCoord += siteWidth; } currCoords.xCoord -= siteWidth; } else //this cell is not the last { double rightCellY = cells[cellInd + 1].GetY(); double rightCellX = cells[cellInd + 1].XCoord; if (rightCellY == startCoords.yCoord) { while (currCoords.xCoord <= (rightCellX - cells[cellInd].width)) { cells[cellInd].XCoord = currCoords.xCoord; double newFuncValue = GetFuncValue(); if (optimalFunc > newFuncValue) { optimalFunc = newFuncValue; optimalCoords.xCoord = currCoords.xCoord; optimalCoords.yCoord = currCoords.yCoord; } currCoords.xCoord += siteWidth; } currCoords.xCoord -= siteWidth; } else { while (currCoords.xCoord <= (windowBounds[rowInd * 2 + 1] - cells[cellInd].width)) { cells[cellInd].XCoord = currCoords.xCoord; double newFuncValue = GetFuncValue(); if (optimalFunc > newFuncValue) { optimalFunc = newFuncValue; optimalCoords.xCoord = currCoords.xCoord; optimalCoords.yCoord = currCoords.yCoord; } currCoords.xCoord += siteWidth; } currCoords.xCoord -= siteWidth; currCoords.xCoord = windowBounds[(rowInd - 1) * 2]; currCoords.yCoord = rightCellY; //m_grid.RowY(rowInd - 1 + firstRow - 1); cells[cellInd].YCoord = currCoords.yCoord; while (currCoords.xCoord <= (rightCellX - cells[cellInd].width)) { cells[cellInd].XCoord = currCoords.xCoord; double newFuncValue = GetFuncValue(); if (optimalFunc > newFuncValue) { optimalFunc = newFuncValue; optimalCoords.xCoord = currCoords.xCoord; optimalCoords.yCoord = currCoords.yCoord; } currCoords.xCoord += siteWidth; } currCoords.xCoord -= siteWidth; } } double delta = optimalFunc - startFunc; double randNumber = rand(); randNumber /= RAND_MAX; if ((delta < 0) || (randNumber < exp(-delta / T))) //if (delta < 0) { cells[cellInd].XCoord = optimalCoords.xCoord; cells[cellInd].YCoord = optimalCoords.yCoord; } else { cells[cellInd].XCoord = startCoords.xCoord; cells[cellInd].YCoord = startCoords.yCoord; } if (optimalFunc < currentMin) { currentMin = optimalFunc; UpdateCellOptimalCoords(); } }