Exemplo n.º 1
0
void Model::addSortedSegment(SegmentModel* m)
{
  insertSegment(m);

  // Add points if necessary
  // If there is an existing previous segment, its end point also exists
  auto createStartPoint = [&]() {
    auto pt = new PointModel{getStrongId(m_points), this};
    pt->setFollowing(m->id());
    pt->setPos(m->start());
    addPoint(pt);
    return pt;
  };
  auto createEndPoint = [&]() {
    auto pt = new PointModel{getStrongId(m_points), this};
    pt->setPrevious(m->id());
    pt->setPos(m->end());
    addPoint(pt);
    return pt;
  };

  if (!m->previous())
  {
    createStartPoint();
  }
  else
  {
    // The previous segment has already been inserted,
    // hence the previous point is present.
    m_points.back()->setFollowing(m->id());
  }

  createEndPoint();
}
Exemplo n.º 2
0
void CurvePresenter::removeSelection()
{
    // We remove all that is selected,
    // And set the bounds correctly
    QSet<id_type<CurveSegmentModel>> segmentsToDelete;

    for(const auto& elt : m_model->selectedChildren())
    {
        if(auto point = dynamic_cast<const CurvePointModel*>(elt))
        {
            if(point->previous())
                segmentsToDelete.insert(point->previous());
            if(point->following())
                segmentsToDelete.insert(point->following());
        }

        if(auto segmt = dynamic_cast<const CurveSegmentModel*>(elt))
        {
            segmentsToDelete.insert(segmt->id());
        }
    }

    QVector<QByteArray> newSegments;
    newSegments.resize(m_model->segments().size() - segmentsToDelete.size());
    int i = 0;
    for(const CurveSegmentModel* segment : m_model->segments())
    {
        if(!segmentsToDelete.contains(segment->id()))
        {
            auto cp = segment->clone(segment->id(), nullptr);
            if(segment->previous() && !segmentsToDelete.contains(segment->previous()))
                cp->setPrevious(segment->previous());
            if(segment->following() && !segmentsToDelete.contains(segment->following()))
                cp->setFollowing(segment->following());

            Serializer<DataStream> s{&newSegments[i++]};
            s.readFrom(*cp);
        }
    }

    m_commandDispatcher.submitCommand(
                new UpdateCurve{
                    iscore::IDocument::path(m_model),
                    std::move(newSegments)
                });
}
Exemplo n.º 3
0
void CurvePresenter::updateSegmentsType(const QString& segmentName)
{
    // They keep their start / end and previous / following but change type.
    // TODO maybe it would be better to encapsulate this ?
    auto factory = SingletonCurveSegmentList::instance().get(segmentName);

    QVector<QByteArray> newSegments;
    newSegments.resize(m_model->segments().size());
    int i = 0;
    for(CurveSegmentModel* segment : m_model->segments())
    {
        CurveSegmentModel* current;
        if(segment->selection.get())
        {
            auto ns = factory->make(segment->id(), nullptr);
            ns->setStart(segment->start());
            ns->setEnd(segment->end());
            ns->setPrevious(segment->previous());
            ns->setFollowing(segment->following());

            current = ns;
        }
        else
        {
            current = segment;
        }

        Serializer<DataStream> s{&newSegments[i++]};
        s.readFrom(*current);
    }

    m_commandDispatcher.submitCommand(
                new UpdateCurve{
                    iscore::IDocument::path(m_model),
                    std::move(newSegments)
                });
}
Exemplo n.º 4
0
void Model::addSegment(SegmentModel* m)
{
  insertSegment(m);

  // Add points if necessary
  // If there is an existing previous segment, its end point also exists
  auto createStartPoint = [&]() {
    auto pt = new PointModel{getStrongId(m_points), this};
    pt->setFollowing(m->id());
    pt->setPos(m->start());
    addPoint(pt);
    return pt;
  };
  auto createEndPoint = [&]() {
    auto pt = new PointModel{getStrongId(m_points), this};
    pt->setPrevious(m->id());
    pt->setPos(m->end());
    addPoint(pt);
    return pt;
  };

  if (m->previous())
  {
    auto previousSegment = std::find_if(
        m_segments.begin(), m_segments.end(), [&](const auto& seg) {
          return seg.following() == m->id();
        });
    if (previousSegment != m_segments.end())
    {
      auto thePt = std::find_if(
          m_points.begin(), m_points.end(), [&](PointModel* pt) {
            return pt->previous() == (*previousSegment).id();
          });

      if (thePt != m_points.end())
      {
        // The previous segments and points both exist
        (*thePt)->setFollowing(m->id());
      }
      else
      {
        // The previous segment exists but not the end point.
        auto pt = createStartPoint();
        pt->setPrevious((*previousSegment).id());
      }
    }
    else // The previous segment has not yet been added.
    {
      createStartPoint();
    }
  }
  else if (std::none_of(m_points.begin(), m_points.end(), [&](PointModel* pt) {
             return pt->following() == m->id();
           }))
  {
    createStartPoint();
  }

  if (m->following())
  {
    auto followingSegment = std::find_if(
        m_segments.begin(), m_segments.end(), [&](const auto& seg) {
          return seg.previous() == m->id();
        });
    if (followingSegment != m_segments.end())
    {
      auto thePt = std::find_if(
          m_points.begin(), m_points.end(), [&](PointModel* pt) {
            return pt->following() == (*followingSegment).id();
          });

      if (thePt != m_points.end())
      {
        (*thePt)->setPrevious(m->id());
      }
      else
      {
        auto pt = createEndPoint();
        pt->setFollowing((*followingSegment).id());
      }
    }
    else
    {
      createEndPoint();
    }
  }
  else if (std::none_of(m_points.begin(), m_points.end(), [&](PointModel* pt) {
             return pt->previous() == m->id();
           }))
  {
    // Note : if one day a buggy case happens here, check that set
    // following/previous
    // are correctly set after cloning the segment.
    createEndPoint();
  }
}