/** \brief When a station has been selected, this updates the shot lines This shows the shot lines from the selected station. If no station is currently selected, this will hide the lines */ void cwScrapStationView::updateShotLines() { if(scrap() == nullptr) { return; } if(scrap()->parentNote() == nullptr) { return; } if(scrap()->parentNote()->parentTrip() == nullptr) { return; } if(transformUpdater() == nullptr) { return; } cwNoteStation noteStation = scrap()->station(selectedItemIndex()); //Get the current trip cwNote* note = scrap()->parentNote(); cwTrip* trip = note->parentTrip(); cwCave* cave = trip->parentCave(); cwStationPositionLookup stationPositionLookup = cave->stationPositionLookup(); //Clear all the lines ShotLines.clear(); if(noteStation.isValid() && stationPositionLookup.hasPosition(noteStation.name())) { QString stationName = noteStation.name(); QSet<cwStation> neighboringStations = trip->neighboringStations(stationName); //The position of the selected station QVector3D selectedStationPos = stationPositionLookup.position(noteStation.name()); //Create the matrix to covert global position into note position QMatrix4x4 noteTransformMatrix = scrap()->noteTransformation()->matrix(); //Matrix from page coordinates to cave coordinates noteTransformMatrix = noteTransformMatrix.inverted(); //From cave coordinates to page coordinates QMatrix4x4 notePageAspect = note->scaleMatrix().inverted(); //The note's aspect ratio QMatrix4x4 offsetMatrix; offsetMatrix.translate(-selectedStationPos); QMatrix4x4 dotPerMeter; dotPerMeter.scale(note->dotPerMeter(), note->dotPerMeter(), 1.0); QMatrix4x4 noteStationOffset; noteStationOffset.translate(QVector3D(noteStation.positionOnNote())); QMatrix4x4 toNormalizedNote = noteStationOffset * dotPerMeter * notePageAspect * noteTransformMatrix * offsetMatrix; //Go through all the neighboring stations and add the position to the line foreach(cwStation station, neighboringStations) { QVector3D currentPos = stationPositionLookup.position(station.name()); QVector3D normalizeNotePos = toNormalizedNote.map(currentPos); ShotLines.append(QLineF(noteStation.positionOnNote(), normalizeNotePos.toPointF())); }
/** \brief When a station has been selected, this updates the shot lines This shows the shot lines from the selected station. If no station is currently selected, this will hide the lines */ void cwScrapStationView::updateShotLines() { if(scrap() == nullptr) { return; } if(scrap()->parentNote() == nullptr) { return; } if(scrap()->parentNote()->parentTrip() == nullptr) { return; } if(transformUpdater() == nullptr) { return; } cwNoteStation noteStation = scrap()->station(selectedItemIndex()); //Get the current trip cwNote* note = scrap()->parentNote(); cwTrip* trip = note->parentTrip(); cwCave* cave = trip->parentCave(); cwStationPositionLookup stationPositionLookup = cave->stationPositionLookup(); //Clear all the lines ShotLines.clear(); if(noteStation.isValid() && stationPositionLookup.hasPosition(noteStation.name())) { QString stationName = noteStation.name(); QSet<cwStation> neighboringStations = trip->neighboringStations(stationName); //The position of the selected station QVector3D selectedStationPos = stationPositionLookup.position(noteStation.name()); //Create the matrix to covert global position into note position QMatrix4x4 noteTransformMatrix = scrap()->noteTransformation()->matrix(); //Matrix from page coordinates to cave coordinates noteTransformMatrix = noteTransformMatrix.inverted(); //From cave coordinates to page coordinates QMatrix4x4 notePageAspect = note->scaleMatrix().inverted(); //The note's aspect ratio QMatrix4x4 offsetMatrix; offsetMatrix.translate(-selectedStationPos); QMatrix4x4 dotPerMeter; dotPerMeter.scale(note->dotPerMeter(), note->dotPerMeter(), 1.0); QMatrix4x4 noteStationOffset; noteStationOffset.translate(QVector3D(noteStation.positionOnNote())); QMatrix4x4 toNormalizedNote = noteStationOffset * dotPerMeter * notePageAspect * noteTransformMatrix * offsetMatrix; //Only used if the scrap is in running profile QMatrix4x4 profileDirection = runningProfileDirection(); //Go through all the neighboring stations and add the position to the line foreach(cwStation station, neighboringStations) { QVector3D currentPos = stationPositionLookup.position(station.name()); if(scrap()->type() == cwScrap::RunningProfile) { bool foundStation = false; foreach(cwNoteStation currentNoteStation, scrap()->stations()) { if(currentNoteStation.name().toLower() == station.name().toLower()) { foundStation = true; } } if(foundStation) { continue; } //Caluclate the running profile rotation based on the stations QMatrix4x4 toProfileRotation = cwScrap::toProfileRotation(selectedStationPos, currentPos); toNormalizedNote = noteStationOffset * dotPerMeter * notePageAspect * noteTransformMatrix * profileDirection * toProfileRotation * offsetMatrix; }