SAMSON Forum
    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • SAMSON Connect
    • Get SAMSON

    The use of displayText function

    GUI
    2
    7
    4584
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      Piriziwè last edited by

      I would like to display a text at the same position as atoms (e.g: display three atoms' serial number). I looked at displayText(std::string text, const SBPosition3 &position, std::string fontFamily, int fontSize, float ∗ color) function but I have some compilation errors. Please, would you mind giving me an example of using this function?

      1 Reply Last reply Reply Quote 0
      • Stephane
        Stephane last edited by Stephane

        Starting with SAMSON 0.6.0, the displayText function takes a QFont instead of a std::string (see the SAMSON class in SDK/0.6.0/include/Facade/SAMSON/SAMSON.hpp, or the documentation at https://documentation.samson-connect.net), to give developers more control. An example would thus be to include the following lines in the display function of e.g. a visual model (derived from SBVisualModel) or a label (derived from SBLabel):

        float color[4] = { 1.0, 1.0, 0.5, 1.0 }; // red, green, blue, alpha
        SAMSON::displayText("Hello world", SBPosition3(SBQuantity::angstrom(0.0), SBQuantity::angstrom(0.0), SBQuantity::angstrom(0.0)), QFont("Segoe UI", 60, 200), color);
        

        This would produce the following text at the origin:
        0_1512049266956_HelloWorld.png

        P 2 Replies Last reply Reply Quote 0
        • P
          Piriziwè @Stephane last edited by

          @stephane-redon Thank you, Sir. It is really helpful

          1 Reply Last reply Reply Quote 0
          • P
            Piriziwè @Stephane last edited by

            @stephane-redon I tried with a visual model and this is what I got as result:
            0_1513092943079_result1.png

            I would like to get this kind of result (for instance: put on each atom its serial number):
            0_1513093026447_image1.png

            Is it possible? I am looking for the way to add a label like SAMSON ruler element does.

            Thank you in advance

            1 Reply Last reply Reply Quote 0
            • Stephane
              Stephane last edited by

              Could you please check to see what happens when you add an atom in the document? There might be an issue when you only have a visual model that displays text, and nothing else. Once this works, it should be easy to position the text on the atoms by sending their position to the displayText function.

              P 1 Reply Last reply Reply Quote 0
              • P
                Piriziwè @Stephane last edited by

                Hi @stephane-redon, sorry for my late response. When I add atoms, nothing happens, they are correctly added.

                I have a visual model that displays arrow on atoms. It reads coordinates from a file and then displays arrows. My problem is that I would like to displays arrows when the user clicks on a button. I tried the way a structural model is added to the active layer programmatically but it does not work. Please, would mind helping me with it?

                This is just an inspiration from how a structural model is added:

                SBMVisualModel* visualModel = new SBMVisualModel();
                visualModel->setName("VP_Arrows");
                
                SAMSON::beginHolding("Display vp by arrows");
                
                SEFleXibleVisualModel vModel; // this is my visual model
                vModel.fileName = vp_file; // this is to set the coordinates file
                
                //visualModel.display(); // I don't know if I need to call this method or not
                visualModel->addChild(vModel); // add my visual model to the SBMVisualModel
                
                visualModel->create();
                SAMSON::getActiveLayer()->addChild(visualModel); // add to the active layer
                

                If this is solved I think I could then display atoms' serial numbers

                Thank you in advance.

                P 1 Reply Last reply Reply Quote 0
                • P
                  Piriziwè @Piriziwè last edited by

                  @Stephane-Redon, it's done :) Thanks. Here's what I did:

                  SEFleXibleVisualModel* model = new SEFleXibleVisualModel(vp_file, "vp"); // my visual model
                  model->setName("VP_Arrows");
                  
                  SAMSON::beginHolding("Display vp by arrows");
                  SAMSON::hold(model);
                  
                  model->create();
                  SAMSON::getActiveLayer()->addChild(model);
                  
                  // stop holding changes to the document
                  SAMSON::endHolding();
                  
                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post