QtPvdbConceptItem::QtPvdbConceptItem(
  const boost::shared_ptr<pvdb::Concept>& concept)
  : m_concept(concept),
    m_indicator_brush(QBrush(QColor(0,0,0,0))),
    m_indicator_pen(QPen(QColor(0,0,0)))
{
  assert(m_concept);
  assert(m_concept->GetExamples());

  this->setFlags(
      QGraphicsItem::ItemIsFocusable
    | QGraphicsItem::ItemIsSelectable);

  //Allow mouse tracking
  this->setAcceptHoverEvents(true);

  this->SetPadding(QtRoundedTextRectItem::Padding(1.0,6.0,1.0,2.0));

  //?FIX 2013-01-06 22:47
  GetConcept()->m_signal_name_changed.connect(
    boost::bind(&QtPvdbConceptItem::OnConceptNameChanged,this)); //Obligatory

  //FIX? 2013-06-25
  //this->SetText("DUMMY TEXT");
  //assert(this->GetText() != m_concept->GetName()
  //  && "The text must be set, to get a resize");
  this->SetText(m_concept->GetName());
}
LiveFunctionWidget::LiveFunctionWidget(Vector2n Position, TypingModule & TypingModule, Project & Project)
	: CompositeWidget(Position, {
		std::shared_ptr<Widget>(m_ToggleWidget = new ToggleWidget(Vector2n(-1, -18), [=](bool State) { m_LiveProgramWidget->m_SourceWidget->m_Visible = State; }, true)),
		std::shared_ptr<Widget>(new FlowLayoutWidget(Vector2n::ZERO, { std::shared_ptr<Widget>(m_InputWidget = new TextFieldWidget(Vector2n::ZERO, TypingModule)),
								   std::shared_ptr<Widget>(m_SourceWidget = new TextFieldWidget(Vector2n::ZERO, TypingModule)),
								   std::shared_ptr<Widget>(m_LiveProgramWidget = new LiveProgramWidget(Vector2n::ZERO, TypingModule, Project)) }, { }))

	}, { std::shared_ptr<Behavior>(new DraggablePositionBehavior(*this)) })
{
	m_LiveProgramWidget->RemoveAllBehaviors();

	// With live test execution and all
	m_SourceWidget->m_OnChange = [=, &Project]()
	{
		std::ostringstream GenProgram;
		Project.GenerateProgramForFunction(GenProgram, m_InputWidget->GetContent(), m_SourceWidget->GetContent());
		m_LiveProgramWidget->m_SourceWidget->SetContent(GenProgram.str());
	};

	m_InputWidget->m_OnChange = m_SourceWidget->m_OnChange;

	{
		auto ImportList = new ListWidget<ConceptId>(Vector2n::ZERO, Project.GetStdIncludes(), TypingModule);
		auto pTypingModule = &TypingModule;
		ImportList->m_TapAction = [=](Vector2n LocalPosition, std::vector<ConceptId> & m_List)
		{
			auto Entry = pTypingModule->TakeString();

			if (!Entry.empty())
			{
				auto ConceptId = FindOrCreateConcept(Entry);

				//Insert(ConceptId);

				// TEST
				auto Spot = m_List.begin() + (LocalPosition.Y() / lineHeight);
				m_List.insert(Spot, ConceptId);
			}
			else
			{
				auto ListEntry = static_cast<decltype(m_List.size())>(LocalPosition.Y() / lineHeight);

				if (ListEntry < m_List.size())
				{
					pTypingModule->SetString(GetConcept(m_List[ListEntry]).GetContent());
					m_List.erase(m_List.begin() + ListEntry);
				}
			}
		};

		auto LabelledImportList = new FlowLayoutWidget(Vector2n(-280, -100), { std::shared_ptr<Widget>(new LabelWidget(Vector2n::ZERO, std::string("import (\""), LabelWidget::Background::None)),
																			   std::shared_ptr<Widget>(ImportList),
																			   std::shared_ptr<Widget>(new LabelWidget(Vector2n::ZERO, std::string("\")"), LabelWidget::Background::None)) }, {});
		static_cast<FlowLayoutWidget *>(GetWidgets()[1].get())->AddWidget(LabelledImportList);
	}
}
QtPvdbEditConceptItem::QtPvdbEditConceptItem(const boost::shared_ptr<pvdb::Concept>& concept)
  : QtPvdbConceptItem(concept)
{
  #ifndef NDEBUG
  Test();
  assert(concept);
  assert(GetConcept());
  #endif

  this->setBrush(QtPvdbBrushFactory::CreateGrayGradientBrush()); //NEW 2013-04-09

  GetConcept()->m_signal_name_changed.connect(
    boost::bind(&QtPvdbEditConceptItem::OnConceptNameChanged,this)); //Obligatory

  //GetConcept()->m_signal_rating_complexity_changed.connect(
  //  boost::bind(&QtPvdbEditConceptItem::UpdateBrushesAndPens,this));
  //GetConcept()->m_signal_rating_concreteness_changed.connect(
  //  boost::bind(&QtPvdbEditConceptItem::UpdateBrushesAndPens,this));
  //GetConcept()->m_signal_rating_specificity_changed.connect(
  //  boost::bind(&QtPvdbEditConceptItem::UpdateBrushesAndPens,this));
}
Ejemplo n.º 4
0
void GenerateProgramForCode(std::ostream & Out, const std::string & Content, std::vector<ConceptId> & Imports)
{
	Out <<
	"package main""\n"
	"""\n"
	"import (""\n";
	for (auto & Import : Imports)
	{
		Out << "	\"" + GetConcept(Import).GetContent() + "\"""\n";
	}
	Out << ")""\n"
	"""\n"
	"func main() {""\n"
	"	" << Content << "\n"
	"}";
}
QtPvdbRateConceptItem::QtPvdbRateConceptItem(const boost::shared_ptr<pvdb::Concept>& concept)
  : QtPvdbConceptItem(concept)
{
  #ifndef NDEBUG
  Test();
  assert(concept);
  assert(GetConcept());
  #endif

  UpdateBrushesAndPens();

  //?FIX 2013-01-06 22:47
  GetConcept()->m_signal_name_changed.connect(
    boost::bind(&QtPvdbRateConceptItem::OnConceptNameChanged,this)); //Obligatory

  GetConcept()->m_signal_examples_changed.connect( //FIX 2013-01-06 22:32
      boost::bind(
        &QtPvdbRateConceptItem::UpdateBrushesAndPens,
        this
      )
    );
  GetConcept()->m_signal_rating_complexity_changed.connect(
      boost::bind(
        &QtPvdbRateConceptItem::UpdateBrushesAndPens,
        this
      )
    );
  GetConcept()->m_signal_rating_concreteness_changed.connect(
      boost::bind(
        &QtPvdbRateConceptItem::UpdateBrushesAndPens,
        this
      )
    );
  GetConcept()->m_signal_rating_specificity_changed.connect(
      boost::bind(
        &QtPvdbRateConceptItem::UpdateBrushesAndPens,
        this
      )
    );

}
Ejemplo n.º 6
0
DimensionsStream & DimensionsStream::operator << (const ConceptId ConceptId)
{
	*this << GetConcept(ConceptId);

	return *this;
}
bool pvdb::ConceptMap::HasSameContent(
  const pvdb::ConceptMap& lhs,
  const pvdb::ConceptMap& rhs)
{
  if (lhs.GetQuestion() != rhs.GetQuestion())
  {
    return false;
  }
  if (lhs.GetEdges().size() != rhs.GetEdges().size())
  {
    return false;
  }
  if (lhs.GetNodes().size() != rhs.GetNodes().size())
  {
    return false;
  }
  //Same Concepts
  {
    const std::vector<boost::shared_ptr<const pvdb::Node> > nodes_lhs = lhs.GetNodes();
    std::multiset<boost::shared_ptr<const pvdb::Concept> > concepts_lhs;
    std::transform(nodes_lhs.begin(),nodes_lhs.end(),
      std::inserter(concepts_lhs,concepts_lhs.begin()),
      [](const boost::shared_ptr<const pvdb::Node>& node)
      {
        assert(node);
        assert(node->GetConcept());
        return node->GetConcept();
      }
    );

    const std::vector<boost::shared_ptr<const pvdb::Node> > nodes_rhs = rhs.GetNodes();

    std::multiset<boost::shared_ptr<const pvdb::Concept> > concepts_rhs;
    std::transform(nodes_rhs.begin(),nodes_rhs.end(),
      std::inserter(concepts_rhs,concepts_rhs.begin()),
      [](const boost::shared_ptr<const pvdb::Node>& node)
      {
        return node->GetConcept();
      }
    );
    if (std::mismatch(concepts_lhs.begin(),concepts_lhs.end(),concepts_rhs.begin(),
      [](const boost::shared_ptr<const pvdb::Concept>& a,
        const boost::shared_ptr<const pvdb::Concept>& b)
        {
          return IsEqual(*a,*b);
        }
      )
      != std::make_pair(concepts_lhs.end(),concepts_rhs.end()))
    {
      return false;
    }
  }
  //Same Edges
  {
    const std::vector<boost::shared_ptr<const pvdb::Edge> > edges_lhs = lhs.GetEdges();
    std::multiset<boost::shared_ptr<const pvdb::Concept> > concepts_lhs;
    std::transform(edges_lhs.begin(),edges_lhs.end(),
      std::inserter(concepts_lhs,concepts_lhs.begin()),
      [](const boost::shared_ptr<const pvdb::Edge>& edge)
      {
        assert(edge);
        assert(edge->GetConcept());
        return edge->GetConcept();
      }
    );

    const std::vector<boost::shared_ptr<const pvdb::Edge> > edges_rhs = rhs.GetEdges();

    std::multiset<boost::shared_ptr<const pvdb::Concept> > concepts_rhs;
    std::transform(edges_rhs.begin(),edges_rhs.end(),
      std::inserter(concepts_rhs,concepts_rhs.begin()),
      [](const boost::shared_ptr<const pvdb::Edge>& edge)
      {
        return edge->GetConcept();
      }
    );
    if (std::mismatch(concepts_lhs.begin(),concepts_lhs.end(),concepts_rhs.begin(),
      [](const boost::shared_ptr<const pvdb::Concept>& a,
        const boost::shared_ptr<const pvdb::Concept>& b)
        {
          return IsEqual(*a,*b);
        }
      )
      != std::make_pair(concepts_lhs.end(),concepts_rhs.end()))
    {
      return false;
    }
  }
  //Check if for each edge a same 'from' and 'to' concept can be found
  {
    typedef std::tuple<std::string,std::string,std::string> FakeEdge;
    typedef std::vector<FakeEdge> FakeEdges;

    assert(lhs.GetEdges().size() == rhs.GetEdges().size());

    FakeEdges v;
    const int sz = lhs.GetEdges().size();
    for (int i=0; i!=sz; ++i)
    {
      const auto from_node = lhs.GetEdges()[i]->GetFrom();
      const std::string str_from = from_node->GetConcept()->GetName();
      const std::string str_mid = lhs.GetEdges()[i]->GetConcept()->GetName();
      const auto to_node = lhs.GetEdges()[i]->GetTo();
      const std::string str_to = to_node->GetConcept()->GetName();
      //Only if arrow is reversed, reverse the fake edge
      if (
           lhs.GetEdges()[i]->HasTailArrow() == true
        && lhs.GetEdges()[i]->HasHeadArrow() == false)
      {
        v.push_back(std::make_tuple(str_to,str_mid,str_from));
      }
      else if (lhs.GetEdges()[i]->HasTailArrow() == lhs.GetEdges()[i]->HasHeadArrow())
      {
        //Two-way or zero-way arrow, add it in both directions
        v.push_back(std::make_tuple(str_to,str_mid,str_from));
        v.push_back(std::make_tuple(str_from,str_mid,str_to));
      }
      else
      {
        //Normal arrow
        v.push_back(std::make_tuple(str_from,str_mid,str_to));
      }
    }
    assert(boost::numeric_cast<int>(v.size()) >= sz);

    FakeEdges w;
    for (int i=0; i!=sz; ++i)
    {
      const auto from_node = rhs.GetEdges()[i]->GetFrom();
      const std::string str_from = from_node->GetConcept()->GetName();
      const std::string str_mid = rhs.GetEdges()[i]->GetConcept()->GetName();
      const auto to_node = rhs.GetEdges()[i]->GetTo();
      const std::string str_to = to_node->GetConcept()->GetName();
      //w.push_back(std::make_tuple(str_from,str_mid,str_to));
      //Only if arrow is reversed, reverse the fake edge
      if (
           rhs.GetEdges()[i]->HasTailArrow() == true
        && rhs.GetEdges()[i]->HasHeadArrow() == false)
      {
        w.push_back(std::make_tuple(str_to,str_mid,str_from));
      }
      else if (rhs.GetEdges()[i]->HasTailArrow() == rhs.GetEdges()[i]->HasHeadArrow())
      {
        //Two-way or zero-way arrow, add it in both directions
        w.push_back(std::make_tuple(str_to,str_mid,str_from));
        w.push_back(std::make_tuple(str_from,str_mid,str_to));
      }
      else
      {
        //Normal arrow
        w.push_back(std::make_tuple(str_from,str_mid,str_to));
      }
    }
    assert(static_cast<int>(w.size()) >= sz);
    if (v.size() != w.size()) return false;

    std::sort(v.begin(),v.end());
    std::sort(w.begin(),w.end());
    if (v != w)
    {
      #ifdef REALLY_SHOW_ME_THIS_7364894385876473475934758934753
      #ifndef NDEBUG
      for (int i=0; i!=sz; ++i)
      {
        std::stringstream s;
        s << "[" << (i+1) << "/" << sz << "]: ("
          << std::get<0>(v[i]) << "," << std::get<1>(v[i]) << "," << std::get<2>(v[i])
          << ") , ("
          << std::get<0>(w[i]) << "," << std::get<1>(w[i]) << "," << std::get<2>(w[i])
          << ")";

      }
      #endif
      #endif
      return false;
    }
  }
  return true;
}
void ConceptStringBoxWidget::ProcessEvent(InputEvent & InputEvent)
{
	if (InputEvent.HasType(InputEvent::EventType::BUTTON_EVENT))
	{
		auto ButtonId = InputEvent.m_InputId;
		bool Pressed = InputEvent.m_Buttons[0];		// TODO: Check if there are >1 buttons

		if (Pointer::VirtualCategory::TYPING == InputEvent.m_Pointer->GetVirtualCategory())
		{
			if (Pressed)
			{
				bool HandledEvent = true;		// Assume true at first

				switch (ButtonId)
				{
				case GLFW_KEY_BACKSPACE:
					/*{
						// Erase the last concept
						if (false == m_Content.empty())
						{
							m_Content.pop_back();
						}

						InputEvent.m_Handled = true;
					}*/
					break;
				case GLFW_KEY_ENTER:
					{
					}
					break;
				case GLFW_KEY_TAB:
					{
					}
					break;
				case GLFW_KEY_LEFT:
					{
						MoveCaretTry(-1, true);
					}
					break;
				case GLFW_KEY_RIGHT:
					{
						MoveCaretTry(+1, true);
					}
					break;
				default:
					HandledEvent = false;
					break;
				}

				if (HandledEvent)
				{
					InputEvent.m_Handled = true;
				}
			}
		}
		else if (Pointer::VirtualCategory::POINTING == InputEvent.m_Pointer->GetVirtualCategory())
		{
			if (HasTypingFocus())
			{
				if (Pressed)
				{
					bool HandledEvent = true;		// Assume true at first

					switch (ButtonId)
					{
					case 0:
						{
							auto Entry = m_TypingModule.TakeString();

							if (!Entry.empty())
							{
								auto ConceptId = FindOrCreateConcept(Entry);

								m_Content.push_back(ConceptId);
							}
							else
							{
								if (!m_Content.empty())
								{
									if (m_CaretPosition >= m_Content.size())
									{
										MoveCaretTry(-1, true);
									}

									m_TypingModule.SetString(GetConcept(m_Content.back()).GetContent());
									m_Content.pop_back();
								}
							}
						}
						break;
					default:
						HandledEvent = false;
						break;
					}

					if (HandledEvent)
					{
						InputEvent.m_Handled = true;
					}
				}
			}
		}
	}
}
Ejemplo n.º 9
0
void ribi::cmap::QtConceptMap::OnNodeKeyDownPressed(QtNode* const item, const int key)
{
  //Note: item can also be the QtNode on a QtEdge
  assert(item);
  if (m_mode == Mode::edit && key == Qt::Key_F2)
  {
    //Edit concept
    QtScopedDisable<QtConceptMap> disable(this);
    QtConceptMapConceptEditDialog d(item->GetNode().GetConcept());
    d.exec();
    //Find the original Node or Edge
    if (::has_custom_vertex_with_my_vertex(item->GetNode(), m_conceptmap))
    {
      assert(::has_custom_vertex_with_my_vertex(item->GetNode(), m_conceptmap));
      const auto vd = ::find_first_custom_vertex_with_my_vertex(item->GetNode(), m_conceptmap);
      //Update the node here
      auto node = item->GetNode();
      node.SetConcept(d.GetConcept());
      //Update the node in the concept map
      set_my_custom_vertex(node, vd, m_conceptmap);
    }
    else
    {
      //It is a node on an edge
      //Find the first (and hopefully only) edge with the node on it
      Node node = item->GetNode();
      const auto ed = ::find_first_custom_edge(
        [node](const Edge& e) { return e.GetNode() == node; },
        m_conceptmap
      );
      //Get hold of the Edge
      Edge edge = ::get_my_custom_edge(ed, m_conceptmap);
      //Update the Edge here
      node.SetConcept(d.GetConcept());
      edge.SetNode(node);
      //Update the node in the concept map
      set_my_custom_edge(edge, ed, m_conceptmap);
    }
    //Update the QtNode
    item->GetNode().SetConcept(d.GetConcept());
    //Set the word-wrapped text
    item->SetText(Wordwrap(d.GetConcept().GetName(), QtNode::GetWordWrapLength()));

  }
  else if (m_mode == Mode::rate && key == Qt::Key_F1)
  {
    //Rate concept
    QtScopedDisable<QtConceptMap> disable(this);
    const auto vd = ::find_first_custom_vertex_with_my_vertex(item->GetNode(), m_conceptmap);
    const auto subgraph = create_direct_neighbour_custom_and_selectable_edges_and_vertices_subgraph(vd, m_conceptmap);
    ribi::cmap::QtRateConceptDialog d(subgraph);
    d.exec();
    if (d.GetOkClicked())
    {
      //Find the original Node
      //const auto vd = FindNode(item->GetNode(), m_conceptmap);
      //Update the node here
      auto node = item->GetNode();
      node.GetConcept().SetRatingComplexity(d.GetComplexity());
      node.GetConcept().SetRatingConcreteness(d.GetConcreteness());
      node.GetConcept().SetRatingSpecificity(d.GetSpecificity());
      //Update the node in the concept map
      set_my_custom_vertex(node, vd, m_conceptmap);
      //Update the QtNode
      item->GetNode().SetConcept(node.GetConcept());
      const int n_rated
        = (node.GetConcept().GetRatingComplexity()   != -1 ? 1 : 0)
        + (node.GetConcept().GetRatingConcreteness() != -1 ? 1 : 0)
        + (node.GetConcept().GetRatingSpecificity()  != -1 ? 1 : 0);
      switch (n_rated)
      {
        case 0:
          item->setBrush(QtBrushFactory().CreateRedGradientBrush());
          break;
        case 1:
        case 2:
          item->setBrush(QtBrushFactory().CreateYellowGradientBrush());
          break;
        case 3:
          item->setBrush(QtBrushFactory().CreateGreenGradientBrush());
          break;
        default: assert(!"Should not get here");
      }
    }
  }
  else if (m_mode == Mode::rate && key == Qt::Key_F2)
  {
    //Rate examples
    if (item->GetNode().GetConcept().GetExamples().Get().empty()) return;
    QtScopedDisable<QtConceptMap> disable(this);
    ribi::cmap::QtRateExamplesDialogNewName d(item->GetNode().GetConcept());
    d.exec();
    //Find the original Node
    const auto vd = ::find_first_custom_vertex_with_my_vertex(item->GetNode(), m_conceptmap);
    //Update the node here
    auto node = item->GetNode();
    node.GetConcept().SetExamples(d.GetRatedExamples());
    //Update the node in the concept map
    set_my_custom_vertex(node, vd, m_conceptmap);
    //Update the QtNode
    item->GetNode().GetConcept().SetExamples(d.GetRatedExamples());
  }

  this->show();
  this->setFocus();
  this->scene()->setFocusItem(item);
  item->setSelected(true);
  this->scene()->update();
}
Ejemplo n.º 10
0
ConceptionApp::ConceptionApp(InputManager & InputManager)
    : App(InputManager),
      m_CurrentProject(),
      m_TypingModule(new TypingModule())		// Gets cleaned up via unique_ptr when pushed back to m_Widgets
{
    PopulateConcepts();

    {
        auto MainCanvas = new Canvas(Vector2n(0, 0), true, true);
        //MainCanvas->MoveView(0, 336);
        MainCanvas->MoveView(1, -64);

#if 1
        {
            auto StdIncludesList = new ListWidget<ConceptId>(Vector2n::ZERO, m_CurrentProject.GetStdIncludes(), *m_TypingModule);
            StdIncludesList->m_TapAction = [=](Vector2n LocalPosition, std::vector<ConceptId> & m_List)
            {
                auto Entry = m_TypingModule->TakeString();

                if (!Entry.empty())
                {
                    auto ConceptId = FindOrCreateConcept(Entry);

                    //Insert(ConceptId);

                    // TEST
                    auto Spot = m_List.begin() + (LocalPosition.Y() / lineHeight);
                    m_List.insert(Spot, ConceptId);
                }
                else
                {
                    auto ListEntry = static_cast<decltype(m_List.size())>(LocalPosition.Y() / lineHeight);

                    if (ListEntry < m_List.size())
                    {
                        m_TypingModule->SetString(GetConcept(m_List[ListEntry]).GetContent());
                        m_List.erase(m_List.begin() + ListEntry);
                    }
                }
            };

            auto LabelledStdIncludesList = new FlowLayoutWidget(Vector2n(-280, -250), { std::shared_ptr<Widget>(new LabelWidget(Vector2n::ZERO, std::string("#include <"), LabelWidget::Background::None)),
                    std::shared_ptr<Widget>(StdIncludesList),
                    std::shared_ptr<Widget>(new LabelWidget(Vector2n::ZERO, std::string(">"), LabelWidget::Background::None))
                                                                                      }, {});
            LabelledStdIncludesList->AddBehavior(std::shared_ptr<Behavior>(new DraggablePositionBehavior(*LabelledStdIncludesList)));
            MainCanvas->AddWidget(LabelledStdIncludesList);
        }
#endif

        MainCanvas->AddWidget(new ButtonWidget(Vector2n(-100, -350), []() {
            std::cout << "Hi from anon func.\n";
        } ));
        MainCanvas->AddWidget(new ButtonWidget(Vector2n(-60, -350), []() {
            std::cout << "Second button.\n";
        } ));
        MainCanvas->AddWidget(new ToggleWidget(Vector2n(-20, -350), [](bool State) {
            std::cout << "Testing this toggle widget! It's now set to " << State << ".\n";
        }, true));
        MainCanvas->AddWidget(new LiveFunctionWidget(Vector2n(-100, 100), *m_TypingModule, m_CurrentProject));
        MainCanvas->AddWidget(new LiveProgramWidget(Vector2n(-100, -300), *m_TypingModule, m_CurrentProject));
        MainCanvas->AddWidget(new LiveProgramWidget(Vector2n(-100, -100), *m_TypingModule, m_CurrentProject));
        MainCanvas->AddWidget(new LiveGofmtWidget(Vector2n(-460, 200), *m_TypingModule, m_CurrentProject));
        MainCanvas->AddWidget(new TextFieldWidget(Vector2n(-460, 160), *m_TypingModule));
        MainCanvas->AddWidget(new ShellWidget(Vector2n(-460, 60), *m_TypingModule));
        MainCanvas->AddWidget(new SayWidget(Vector2n(-460, -100), *m_TypingModule));

        MainCanvas->AddWidget(new ConceptStringBoxWidget(Vector2n(-400, 100 + 400), *m_TypingModule));

        // TEST: Modify some Concept
        {
            auto Widget = new TextFieldWidget(Vector2n(-320, 470), *m_TypingModule);
            Widget->SetContent(GetConcept(47).GetContent());
            Widget->m_OnChange = [=]() {
                static_cast<ConceptBasic &>(ModifyConcept(47)).SetContentTEST(Widget->GetContent());
            };
            Widget->AddBehavior(std::shared_ptr<Behavior>(new DraggablePositionBehavior(*Widget)));
            MainCanvas->AddWidget(Widget);
        }

        // Label resizing test
        {
            auto SourceWidget = new TextFieldWidget(Vector2n::ZERO, *m_TypingModule);

            auto Content = [=]() -> std::string {
                return SourceWidget->GetContent();
            };
            auto LabelWidget = new class LabelWidget(Vector2n::ZERO, Content, LabelWidget::Background::Normal);

            MainCanvas->AddWidget(new FlowLayoutWidget(Vector2n(-100, -450), { std::shared_ptr<Widget>(SourceWidget), std::shared_ptr<Widget>(LabelWidget) }, {}));
        }

        // Time widget
        {
            auto Content = []() -> std::string {
                auto now = std::chrono::system_clock::now();

                auto duration = now.time_since_epoch();

                auto seconds = std::chrono::duration_cast<std::chrono::seconds>(duration).count();

                return std::to_string(seconds);
            };
            auto LabelWidget = new class LabelWidget(Vector2n(360, -340), Content, LabelWidget::Background::Normal);
            LabelWidget->AddBehavior(std::shared_ptr<Behavior>(new DraggablePositionBehavior(*LabelWidget)));

            MainCanvas->AddWidget(LabelWidget);
        }

        MainCanvas->AddWidget(new TimeWidget(Vector2n(360, -360)));		// Time widget

#if 0
        // "./GenProgram.go" file contents displayed (in real-time) in this Label Widget
        {
            auto Content = []() -> std::string {
                //return FromFileToString("./GenProgram.go");
                return FromFileToString("/Users/Dmitri/Desktop/goproj_play/src/gist.github.com/4670289.git/gistfile1.go");
            };
            auto LabelWidget = new class LabelWidget(Vector2n(-546, -186), Content, LabelWidget::Background::Normal);
            LabelWidget->AddBehavior(std::shared_ptr<Behavior>(new DraggablePositionBehavior(*LabelWidget)));

            MainCanvas->AddWidget(LabelWidget);
        }
#endif

#if 1
        {
            MainCanvas->AddWidget(new ListWidget<Concept *>(Vector2n(-730 - 450, -250), Concepts, *m_TypingModule));
        }
#endif

        m_Widgets.push_back(std::unique_ptr<Widget>(m_TypingModule));

        m_Widgets.push_back(std::unique_ptr<Widget>(MainCanvas));

        m_Widgets.push_back(std::unique_ptr<Widget>(new DebugOverlayWidget()));		// DEBUG: Print debug info
    }

    // Prepare and start the thread
    {
        m_CurrentProject.StartBackgroundThread();
    }

    {
        // Load program
        m_CurrentProject.LoadSampleGenProgram(*static_cast<Canvas *>(m_Widgets[0].get()));
    }
}
Ejemplo n.º 11
0
OpenGLStream & OpenGLStream::operator << (const ConceptId ConceptId)
{
	*this << GetConcept(ConceptId);

	return *this;
}
void QtPvdbRateConceptItem::UpdateBrushesAndPens()
{
  //Brush for the concept being rated
  const int n_rated
    = (GetConcept()->GetRatingComplexity()   != -1 ? 1 : 0)
    + (GetConcept()->GetRatingConcreteness() != -1 ? 1 : 0)
    + (GetConcept()->GetRatingSpecificity()  != -1 ? 1 : 0);

  switch (n_rated)
  {
    case 0:
      this->SetMainBrush(QtPvdbBrushFactory::CreateRedGradientBrush());
      break;
    case 1:
    case 2:
      this->SetMainBrush(QtPvdbBrushFactory::CreateYellowGradientBrush());
      break;
    case 3:
      this->SetMainBrush(QtPvdbBrushFactory::CreateGreenGradientBrush());
      break;
    default: assert(!"Should not get here");
  }
  //Brush and pen for the examples being rated
  if (GetConcept()->GetExamples()->Get().empty())
  {
    //No examples
    this->SetIndicatorBrush(QBrush(QColor(0,0,0)));
    this->SetIndicatorPen(QPen(QColor(0,0,0)));
  }
  else
  {
    const std::vector<boost::shared_ptr<const pvdb::Example> > v = AddConst(GetConcept()->GetExamples()->Get());
    const int n_examples = static_cast<int>(v.size());
    const int n_judged
      = std::count_if(v.begin(),v.end(),
        [](const boost::shared_ptr<const pvdb::Example>& p)
        {
          assert(p);
          const pvdb::Competency this_competency = p->GetCompetency();
          return this_competency != pvdb::Competency::uninitialized;
        }
      );
    if (n_judged == 0)
    {
      this->SetIndicatorBrush(QBrush(QColor(255,128,128)  )); //Red
      this->SetIndicatorPen(  QPen(  QColor(255,  0,  0),3)); //Thick pen
    }
    else if (n_judged < n_examples)
    {
      this->SetIndicatorBrush(QBrush(QColor(255,196,128)  )); //Orange
      this->SetIndicatorPen(  QPen(  QColor(255,196,  0),2)); //Less thick pen
    }
    else
    {
      assert(n_judged == n_examples);
      this->SetIndicatorBrush(QBrush(QColor(128,255,128)  )); //Green
      this->SetIndicatorPen(  QPen(  QColor(  0,255,  0),1)); //Thin pen
    }
  }
  //this->update(); //FIX 2013-01-17
  //this->m_signal_item_has_updated(this); //FIX 2013-01-17
  //this->m_signal_request_scene_update(); //FIX 2013-01-17
}
void QtPvdbDisplayConceptItem::UpdateBrushesAndPens()
{
  assert(GetConcept());
  assert(GetConcept()->GetExamples());

  //Brush for the concept being rated
  QBrush new_main_brush = this->brush();
  {
    const int n_rated
      = (GetConcept()->GetRatingComplexity()   != -1 ? 1 : 0)
      + (GetConcept()->GetRatingConcreteness() != -1 ? 1 : 0)
      + (GetConcept()->GetRatingSpecificity()  != -1 ? 1 : 0);
    switch (n_rated)
    {
      case 0:
        new_main_brush = QtPvdbBrushFactory::CreateRedGradientBrush();
        break;
      case 1:
      case 2:
        new_main_brush = QtPvdbBrushFactory::CreateYellowGradientBrush();
        break;
      case 3:
        new_main_brush = QtPvdbBrushFactory::CreateGreenGradientBrush();
        break;
      default: assert(!"Should not get here");
    }
  }
  //Brush and pen for the examples being rated
  QBrush new_indicator_brush = this->GetIndicatorBrush();
  QPen new_indicator_pen = this->GetIndicatorPen();
  if (GetConcept()->GetExamples()->Get().empty())
  {
    //No examples
    new_indicator_brush = QBrush(QColor(0,0,0));
    new_indicator_pen = QPen(QColor(0,0,0));
  }
  else
  {
    const std::vector<boost::shared_ptr<const pvdb::Example> > v = AddConst(GetConcept()->GetExamples()->Get());
    const int n_examples = boost::numeric_cast<int>(v.size());
    const int n_judged
      = std::count_if(v.begin(),v.end(),
        [](const boost::shared_ptr<const pvdb::Example>& p)
        {
          assert(p);
          const pvdb::Competency this_competency = p->GetCompetency();
          return this_competency != pvdb::Competency::uninitialized;
        }
      );
    if (n_judged == 0)
    {
      new_indicator_brush = QBrush(QColor(255,128,128)); //Red
    }
    else if (n_judged < n_examples)
    {
      new_indicator_brush = QBrush(QColor(255,196,128)); //Orange
    }
    else
    {
      assert(n_judged == n_examples);
      new_indicator_brush = QBrush(QColor(128,255,128)); //Green
    }
    if (n_judged == 0)
    {
      new_indicator_pen = QPen(QColor(255,0,0),3); //Thick pen
    }
    else if (n_judged < n_examples)
    {
      new_indicator_pen = QPen(QColor(255,196,0),2); //Less thick pen
    }
    else
    {
      assert(n_judged == n_examples);
      new_indicator_pen = QPen(QColor(0,255,0),1); //Thin pen
    }
  }

  if (this->brush() != new_main_brush
    || this->GetIndicatorBrush() != new_indicator_brush
    || this->GetIndicatorPen() != new_indicator_pen)
  {
    this->setBrush(new_main_brush);
    this->SetIndicatorBrush(new_indicator_brush);
    this->SetIndicatorPen(new_indicator_pen);
    assert(this->brush() == new_main_brush);
    assert(this->GetIndicatorBrush() == new_indicator_brush);
    assert(this->GetIndicatorPen() == new_indicator_pen);
    //TRACE(std::rand()); //GOOD: Detects infinite recursion
    //this->update();
    this->m_signal_item_has_updated(this); //Obligatory
    this->m_signal_request_scene_update(); //Obligatory
  }
}